Work on the intro and the index chapter

This commit is contained in:
blinry 2021-01-11 19:16:35 +01:00
parent 4910e4d566
commit 8d333ce56a
31 changed files with 327 additions and 185 deletions

View file

@ -1,10 +1,12 @@
title = Updating files in the index
cards = add
cards = add commit checkout
[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!
The command for this is the same - `git add`!
[setup]
@ -17,5 +19,20 @@ git commit -m "Initial commit"
[win]
# Make changes to all three files, and add all of them to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3
# 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]
Well done! Try tavelling between the commits using `git checkout`, so you can look at their contents again!

29
levels/index/auto Normal file
View file

@ -0,0 +1,29 @@
title = Capturing the status quo
cards = file-new file-delete commit-auto
[description]
So far, you have made commits using a pretty convenient command, which captures the complete working directory as it is in a commit. See how the card says something about "add"?
Let's try using that one again! (Only pay attention to the white, actual files for now!)
[setup]
echo a > a
echo b > b
echo c > c
git add .
git commit -m "Initial commit"
git commit -m "Nothing changed" --allow-empty
[win]
# Make a single commit where you modify a file ...
git show --name-status --oneline | grep '^M '
# ... add a new file ...
git show --name-status --oneline | grep '^A '
# ... and delete a file.
git show --name-status --oneline | grep '^D '

View file

@ -1,10 +1,12 @@
title = Checking out files from the index
cards = add reset checkout
cards = add reset checkout-file commit
[description]
So you've made changes to your files, but you decide that you don't want to keep them! You can use `git checkout` for that!
What happens if you have already update the index, like in file c? You have to reset the index first!
[setup]
echo a > a
@ -14,6 +16,8 @@ git add .
git commit -m "Initial commit"
echo x > a
echo x > b
echo x > c
git add c
[win]

View file

@ -1,27 +0,0 @@
title = Make a commit \o/
cards = add reset checkout commit
[description]
With that, we're ready to make our first commit! It will contain the version of the files which are currently in the index.
[setup]
echo a > a
echo x > b
echo x > c
git add .
git commit -m "Initial commit"
echo x > a
echo b > b
git add b
echo c > c
[win]
# File a contains "x" in the last main commit.
test "$(git show main:a)" = x
# File b contains "x" in the last main commit.
test "$(git show main:b)" = x
# File c contains "x" in the last main commit.
test "$(git show main:c)" = x

View file

@ -1,26 +0,0 @@
title = Make a commit, but faster!
cards = add reset checkout commit commit-a
[description]
There is a time-saving trick, where instead of a plain `git commit`, you can use
git commit -a
This will automatically add all changes you made to local files! Very convenient.
[setup]
echo a > a
echo b > b
echo c > c
git add .
git commit -m "Initial commit"
echo x > a
echo x > b
echo x > c
[win]
# Make a commit where all files contain "x".
test "$(git show main:a)" = x && test "$(git show main:b)" = x && test "$(git show main:c)" = x

View file

@ -1,5 +1,5 @@
title = Rename a file in the next commit
cards = add reset checkout mv commit
cards = add reset checkout-file mv commit
[description]

View file

@ -1,11 +1,17 @@
title = Add new files to the index
cards = add
cards = add commit
[description]
In the index, we can prepare what will be in the next commit.
But Git allows to you capture changes with more precision!
Initially, the index will be empty, and all files are untracked. If you have a file, and you want to have it in the next commit, use `git add`!
To understand how to do that, you need to learn about [your teacher raises her voice dramatically] *the index*!
In the index, we can prepare what will be in the next commit. In this game, the index is represented by a blue aura!
Initially, all files are untracked. If you have a file, and you want to have it in the next commit, use `git add`!
Here, we don't use the fancy commit card, but a plain `git commit`!
[setup]
@ -16,4 +22,7 @@ echo c > c
[win]
# Add all three files to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3
test "$(git ls-files | wc -l)" -eq 3
# And make a commit.
test "$(git ls-tree main | wc -l)" -eq 3

View file

@ -1,9 +1,11 @@
title = Resetting files in the index
cards = add reset
cards = add reset commit
[description]
If you already have changes in the index, but want to reset them, you can use `git reset`!
See the dark shadow behind the icons? That's the version of the commit you're at!
If you already have updated the index to a changed file, but want to reset it, you can use `git reset`!
[setup]
@ -14,9 +16,17 @@ git add .
git commit -m "Initial commit"
echo x > a
echo x > b
echo x > c
git add .
[win]
# Reset all changes in files in the index!
test "$(git diff --cached --name-only | wc -l)" -eq 0
# Reset the changes in a and c
test "$(git show :a)" == "a" &&
test "$(git show :b)" != "a" &&
test "$(git show :c)" == "c"
# And make a commit!
test "$(git show main:a)" == "a" &&
test "$(git show main:b)" != "b" &&
test "$(git show main:c)" == "c"

View file

@ -1,5 +1,5 @@
title = Delete a file in the next commit
cards = add reset checkout rm commit
cards = add reset checkout-file rm file-delete commit
[description]

View file

@ -1,8 +1,7 @@
auto
new
add
reset
checkout
commit
commit-a
rm
mv