mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-24 16:20:08 +01:00
First storification of the index chapter
This commit is contained in:
parent
01d8fe3d3e
commit
09bbf7a0ad
9 changed files with 136 additions and 52 deletions
|
@ -1,29 +0,0 @@
|
||||||
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 '
|
|
25
levels/index/change
Normal file
25
levels/index/change
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
title = Update files in the index
|
||||||
|
cards = add commit
|
||||||
|
|
||||||
|
[description]
|
||||||
|
|
||||||
|
When we change files, the index won't change on its own. We have to use `git add` to update the index to the changed version of the file.
|
||||||
|
|
||||||
|
Let's try that!
|
||||||
|
|
||||||
|
[setup]
|
||||||
|
|
||||||
|
echo "The candle is burning with a blue flame." > candle
|
||||||
|
git add .
|
||||||
|
git commit -m "The beginning"
|
||||||
|
|
||||||
|
[win]
|
||||||
|
|
||||||
|
# Make a change to the candle.
|
||||||
|
test "$(git diff --name-only)" = "candle" || file -f .git/candle-changed && touch .git/candle-changed
|
||||||
|
|
||||||
|
# Add the candle.
|
||||||
|
test "$(git diff --cached --name-only)" = "candle" || file -f .git/candle-added && touch .git/candle-added
|
||||||
|
|
||||||
|
# Make a commit.
|
||||||
|
test "$(git diff --name-only HEAD HEAD^)" = "candle"
|
45
levels/index/compare
Normal file
45
levels/index/compare
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
title = Step by step
|
||||||
|
cards = checkout
|
||||||
|
|
||||||
|
[description]
|
||||||
|
|
||||||
|
Welcome to today's lesson! Today, we're going to learn how to make commits with precision!
|
||||||
|
|
||||||
|
Have a look at these two timelines. They have exactly the same outcome. But one of them makes it much easier to figure out what happened.
|
||||||
|
|
||||||
|
[setup]
|
||||||
|
|
||||||
|
echo "A small, but heavy glass ball." > ball
|
||||||
|
echo "A thin book, that's standing upright." > book
|
||||||
|
echo "A candle, burning with a blue flame." > candle
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m "The beginning"
|
||||||
|
|
||||||
|
git branch -M all-at-once
|
||||||
|
|
||||||
|
echo "The ball is now touching the book." > ball
|
||||||
|
echo "The book has fallen over." > book
|
||||||
|
echo "The candle has been blown out." > candle
|
||||||
|
|
||||||
|
git commit -am "The end"
|
||||||
|
|
||||||
|
git checkout HEAD^
|
||||||
|
|
||||||
|
git checkout -b step-by-step
|
||||||
|
|
||||||
|
echo "The ball is now touching the book." > ball
|
||||||
|
git commit -am "The ball rolls towards the book"
|
||||||
|
|
||||||
|
echo "The book has fallen over." > book
|
||||||
|
git commit -am "The book falls over"
|
||||||
|
|
||||||
|
echo "The candle has been blown out." > candle
|
||||||
|
git commit -am "The book blows out the candle"
|
||||||
|
|
||||||
|
git checkout HEAD~3
|
||||||
|
|
||||||
|
[win]
|
||||||
|
|
||||||
|
# This level doesn't have a goal yet.
|
||||||
|
false
|
|
@ -3,26 +3,20 @@ cards = add commit
|
||||||
|
|
||||||
[description]
|
[description]
|
||||||
|
|
||||||
But Git allows to you capture changes with more precision!
|
So far, when we made a commit, we've always recorded the current status all objects, right?
|
||||||
|
|
||||||
To understand how to do that, you need to learn about [your teacher raises her voice dramatically] *the index*!
|
But Git allows you to pick which changes you want to put in a commit!
|
||||||
|
|
||||||
In the index, we can prepare what will be in the next commit. In this game, the index is represented by a blue aura!
|
To learn how that works, we need to learn about 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]
|
[setup]
|
||||||
|
|
||||||
echo a > a
|
echo "The candle is burning with a blue flame." > candle
|
||||||
echo b > b
|
|
||||||
echo c > c
|
|
||||||
|
|
||||||
[win]
|
[win]
|
||||||
|
|
||||||
# Add all three files to the index.
|
# Add the candle.
|
||||||
test "$(git ls-files | wc -l)" -eq 3
|
test "$(git diff --cached --name-only)" = "candle" || file -f .git/candle-added && touch .git/candle-added
|
||||||
|
|
||||||
# And make a commit.
|
# Make a commit.
|
||||||
test "$(git ls-tree main | wc -l)" -eq 3
|
test "$(git ls-tree --name-only HEAD)" = "candle"
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
auto
|
compare
|
||||||
new
|
new
|
||||||
add
|
change
|
||||||
reset
|
steps
|
||||||
checkout
|
|
||||||
rm
|
|
||||||
|
|
53
levels/index/steps
Normal file
53
levels/index/steps
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
title = Adding changes step by step
|
||||||
|
cards = add 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]
|
||||||
|
|
||||||
|
echo "A small, but heavy glass ball. It is not touching the book." > ball
|
||||||
|
echo "A thin book, that's standing upright." > book
|
||||||
|
echo "A candle, burning with a blue flame." > candle
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m "The beginning"
|
||||||
|
|
||||||
|
[win]
|
||||||
|
|
||||||
|
# Make changes to all three objects!
|
||||||
|
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
|
|
@ -2,3 +2,4 @@ risky
|
||||||
copies
|
copies
|
||||||
git
|
git
|
||||||
remote
|
remote
|
||||||
|
who-are-you
|
||||||
|
|
|
@ -3,6 +3,3 @@ files
|
||||||
branches
|
branches
|
||||||
merge
|
merge
|
||||||
index
|
index
|
||||||
remotes
|
|
||||||
changing-the-past
|
|
||||||
bisect
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ func load(path):
|
||||||
level_names.erase(level)
|
level_names.erase(level)
|
||||||
final_level_sequence.push_back(level)
|
final_level_sequence.push_back(level)
|
||||||
|
|
||||||
final_level_sequence += level_names
|
#final_level_sequence += level_names
|
||||||
|
|
||||||
for l in final_level_sequence:
|
for l in final_level_sequence:
|
||||||
var level = Level.new()
|
var level = Level.new()
|
||||||
|
|
Loading…
Reference in a new issue