oh-my-git/levels/en_EN/index/steps

54 lines
1.6 KiB
Text
Raw Normal View History

title = Adding changes step by step
2021-02-04 12:01:58 +01:00
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]
2021-02-04 12:01:58 +01:00
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]
2021-02-04 12:01:58 +01:00
# 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