First version of an "index" chapter

This commit is contained in:
blinry 2021-01-05 12:46:07 +01:00
parent 21d8366dbb
commit e754671b88
12 changed files with 216 additions and 6 deletions

21
levels/index/add Normal file
View file

@ -0,0 +1,21 @@
title = Updating files in the index
cards = add
[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.
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 three files, and add all of them to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3

21
levels/index/checkout Normal file
View file

@ -0,0 +1,21 @@
title = Checking out files from the index
cards = add reset checkout
[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!
[setup]
echo a > a
echo b > b
echo c > c
git add .
git commit -m "Initial commit"
echo x > a
echo x > b
[win]
# Remove all changes in your local files!
test "$(git diff --name-only | wc -l)" -eq 0

27
levels/index/commit Normal file
View file

@ -0,0 +1,27 @@
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

26
levels/index/commit-a Normal file
View file

@ -0,0 +1,26 @@
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

26
levels/index/mv Normal file
View file

@ -0,0 +1,26 @@
title = Rename a file in the next commit
cards = add reset checkout mv commit
[description]
Other times, you might want to rename a file in the next commit. Use
git mv [file] [new name]
for that. The effect is very similar as if you had created a copy with a new name, and removed the old version.
[setup]
echo a > a
echo SPECIAL > b
echo x > c
git add .
git commit -m "Initial commit"
echo x > a
echo b >> b
git add b
[win]
# Make a commit where you rename the file b to "x".
test "$(git ls-tree --name-only main)" = "$(echo -e "a\nc\nx")"

19
levels/index/new Normal file
View file

@ -0,0 +1,19 @@
title = Add new files to the index
cards = add
[description]
In the index, we can prepare what will be in the next commit.
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`!
[setup]
echo a > a
echo b > b
echo c > c
[win]
# Add all three files to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3

22
levels/index/reset Normal file
View file

@ -0,0 +1,22 @@
title = Resetting files in the index
cards = add reset
[description]
If you already have changes in the index, but want to reset them, you can use `git reset`!
[setup]
echo a > a
echo b > b
echo c > c
git add .
git commit -m "Initial commit"
echo x > a
echo x > b
git add .
[win]
# Reset all changes in files in the index!
test "$(git diff --cached --name-only | wc -l)" -eq 0

24
levels/index/rm Normal file
View file

@ -0,0 +1,24 @@
title = Delete a file in the next commit
cards = add reset checkout rm commit
[description]
If you want to remove a file in the next commit, you can use `git rm`! This will both delete the file locally, and in the index.
If a file is modified, you'll need to reset these changes first/reset the files.
[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
[win]
# Make a commit where all files are deleted ¯\_(^_^)_/¯
test "$(git ls-tree main | wc -l)" -eq 0

8
levels/index/sequence Normal file
View file

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

View file

@ -1,2 +1,3 @@
index
time-machine
low-level

View file

@ -6,8 +6,13 @@
},
{
"id": "checkout",
"command": "git checkout [commit, ref]",
"description": "Drag this card to a commit or to a branch to travel to it!"
"command": "git checkout [commit, ref, file]",
"description": "Drag this card to a commit or to a branch to travel to it!\n\nAlternatively, reset changes in a local file."
},
{
"id": "commit-a",
"command": "git commit -a",
"description": "Make a new commit, after automatically adding all changes to the index.\nYou'll be asked to enter a short description of what you changed."
},
{
"id": "commit-auto",
@ -51,8 +56,8 @@
},
{
"id": "reset",
"command": "git reset [commit]",
"description": "Jump to the commit, and update the index. Keep the current environment."
"command": "git reset [commit, file]",
"description": "Jump to the commit, and update the index. Keep the current environment.\n\nAlternatively, reset changes in a file in the index."
},
{
"id": "cherry-pick",
@ -79,6 +84,16 @@
"command": "git add [file]",
"description": "Put the current status of the file into the plan."
},
{
"id": "rm",
"command": "git rm [file]",
"description": "Delete a file both in the working directory, as well as the index."
},
{
"id": "mv",
"command": "git mv [file] [string]",
"description": "DOESN'T WORK YET\n\nRename a file both in the working directory, as well as the index."
},
{
"id": "commit",
"command": "git commit",

View file

@ -61,13 +61,13 @@ __meta__ = {
}
[node name="Button" type="Button" parent="VBoxContainer"]
margin_right = 352.0
margin_right = 351.0
margin_bottom = 39.0
text = "Levels"
[node name="Button2" type="Button" parent="VBoxContainer"]
margin_top = 44.0
margin_right = 352.0
margin_right = 351.0
margin_bottom = 83.0
text = "Quit"
[connection signal="pressed" from="VBoxContainer/Button" to="." method="levels"]