From e754671b88655f883e69187059f6bee4572d8404 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 5 Jan 2021 12:46:07 +0100 Subject: [PATCH] First version of an "index" chapter --- levels/index/add | 21 +++++++++++++++++++++ levels/index/checkout | 21 +++++++++++++++++++++ levels/index/commit | 27 +++++++++++++++++++++++++++ levels/index/commit-a | 26 ++++++++++++++++++++++++++ levels/index/mv | 26 ++++++++++++++++++++++++++ levels/index/new | 19 +++++++++++++++++++ levels/index/reset | 22 ++++++++++++++++++++++ levels/index/rm | 24 ++++++++++++++++++++++++ levels/index/sequence | 8 ++++++++ levels/sequence | 1 + resources/cards.json | 23 +++++++++++++++++++---- scenes/title.tscn | 4 ++-- 12 files changed, 216 insertions(+), 6 deletions(-) create mode 100644 levels/index/add create mode 100644 levels/index/checkout create mode 100644 levels/index/commit create mode 100644 levels/index/commit-a create mode 100644 levels/index/mv create mode 100644 levels/index/new create mode 100644 levels/index/reset create mode 100644 levels/index/rm create mode 100644 levels/index/sequence diff --git a/levels/index/add b/levels/index/add new file mode 100644 index 0000000..ddbc61a --- /dev/null +++ b/levels/index/add @@ -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 diff --git a/levels/index/checkout b/levels/index/checkout new file mode 100644 index 0000000..491fc32 --- /dev/null +++ b/levels/index/checkout @@ -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 diff --git a/levels/index/commit b/levels/index/commit new file mode 100644 index 0000000..7d3071b --- /dev/null +++ b/levels/index/commit @@ -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 diff --git a/levels/index/commit-a b/levels/index/commit-a new file mode 100644 index 0000000..747a009 --- /dev/null +++ b/levels/index/commit-a @@ -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 diff --git a/levels/index/mv b/levels/index/mv new file mode 100644 index 0000000..53c2da1 --- /dev/null +++ b/levels/index/mv @@ -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")" diff --git a/levels/index/new b/levels/index/new new file mode 100644 index 0000000..b46898b --- /dev/null +++ b/levels/index/new @@ -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 diff --git a/levels/index/reset b/levels/index/reset new file mode 100644 index 0000000..9baf28b --- /dev/null +++ b/levels/index/reset @@ -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 diff --git a/levels/index/rm b/levels/index/rm new file mode 100644 index 0000000..df769f3 --- /dev/null +++ b/levels/index/rm @@ -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 diff --git a/levels/index/sequence b/levels/index/sequence new file mode 100644 index 0000000..7a4987c --- /dev/null +++ b/levels/index/sequence @@ -0,0 +1,8 @@ +new +add +reset +checkout +commit +commit-a +rm +mv diff --git a/levels/sequence b/levels/sequence index f159582..49acab7 100644 --- a/levels/sequence +++ b/levels/sequence @@ -1,2 +1,3 @@ +index time-machine low-level diff --git a/resources/cards.json b/resources/cards.json index c865647..f86aed1 100644 --- a/resources/cards.json +++ b/resources/cards.json @@ -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", diff --git a/scenes/title.tscn b/scenes/title.tscn index 98c8a01..05b21a8 100644 --- a/scenes/title.tscn +++ b/scenes/title.tscn @@ -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"]