oh-my-git/levels/index/add

39 lines
1 KiB
Plaintext
Raw Normal View History

2021-01-05 12:46:07 +01:00
title = Updating files in the index
cards = add commit checkout
2021-01-05 12:46:07 +01:00
[description]
So you start working, and make changes to your files! Git lets you choose which of these changes you want to put in the next commit. This is like updating the index version of that file to the new version.
This allows you to have smaller commits, that describe better what you changed!
2021-01-05 12:46:07 +01:00
The command for this is the same - `git add`!
[setup]
echo a > a
echo b > b
echo c > c
git add .
git commit -m "Initial commit"
[win]
# Make changes to all files!
test "$(cat a)" != "a" &&
test "$(cat b)" != "b" &&
test "$(cat c)" != "c"
# Add only the changes of a and c, and make a commit! Finally, make a commit which captures the changes in b!
test "$(git show main:a)" != "a" &&
test "$(git show main:b)" != "b" &&
test "$(git show main:c)" != "c" &&
test "$(git show main^:a)" != "a" &&
test "$(git show main^:b)" == "b" &&
test "$(git show main^:c)" != "c"
[congrats]
2024-02-12 04:54:11 +01:00
Well done! Try travelling between the commits using `git checkout`, so you can look at their contents again!