mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-05-07 05:02:04 +02:00
First storification of the index chapter
This commit is contained in:
parent
01d8fe3d3e
commit
09bbf7a0ad
9 changed files with 136 additions and 52 deletions
levels/index
53
levels/index/steps
Normal file
53
levels/index/steps
Normal file
|
@ -0,0 +1,53 @@
|
|||
title = Adding changes step by step
|
||||
cards = add commit
|
||||
|
||||
[description]
|
||||
|
||||
The index is really useful, because it allows us to be precise about which changes we want to include in each commit!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "A small, but heavy glass ball. It is not touching the book." > ball
|
||||
echo "A thin book, that's standing upright." > book
|
||||
echo "A candle, burning with a blue flame." > candle
|
||||
|
||||
git add .
|
||||
git commit -m "The beginning"
|
||||
|
||||
[win]
|
||||
|
||||
# Make changes to all three objects!
|
||||
test "$(git diff --name-only | wc -l)" -eq 3 || file -f .git/candle-changed && touch .git/candle-changed
|
||||
|
||||
# Only add one of these changes!
|
||||
test "$(git diff --cached --name-only | wc -l)" -eq 1 || file -f .git/candle-added && touch .git/candle-added
|
||||
|
||||
# And make a commit.
|
||||
COUNT=0
|
||||
for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do
|
||||
if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then
|
||||
COUNT=$((COUNT+1))
|
||||
fi
|
||||
done
|
||||
|
||||
test "$COUNT" -ge 1
|
||||
|
||||
# Make a second commit that only records a single change.
|
||||
COUNT=0
|
||||
for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do
|
||||
if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then
|
||||
COUNT=$((COUNT+1))
|
||||
fi
|
||||
done
|
||||
|
||||
test "$COUNT" -ge 2
|
||||
|
||||
# And a third one.
|
||||
COUNT=0
|
||||
for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do
|
||||
if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then
|
||||
COUNT=$((COUNT+1))
|
||||
fi
|
||||
done
|
||||
|
||||
test "$COUNT" -ge 3
|
Loading…
Add table
Add a link
Reference in a new issue