oh-my-git/levels/index/steps
2021-02-04 12:02:15 +01:00

54 lines
1.6 KiB
Plaintext

title = Adding changes step by step
cards = add reset-file 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 hammer, balancing on its handle." > hammer
echo "A bottle, containing a clear liquid." > bottle
echo "A white sugar cube." > sugar_cube
git add .
git commit -m "The beginning"
[win]
# Make changes to all three objects, to form a logical sequence of events!
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