mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-06-01 19:19:31 +02:00
finished the mechanism for setting the language
This commit is contained in:
parent
705cc849c2
commit
50ee071f0e
214 changed files with 94 additions and 10 deletions
38
levels/en_EN/index/add
Normal file
38
levels/en_EN/index/add
Normal file
|
@ -0,0 +1,38 @@
|
|||
title = Updating files in the index
|
||||
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]
|
||||
|
||||
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]
|
||||
|
||||
Well done! Try tavelling between the commits using `git checkout`, so you can look at their contents again!
|
31
levels/en_EN/index/change
Normal file
31
levels/en_EN/index/change
Normal file
|
@ -0,0 +1,31 @@
|
|||
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!
|
||||
|
||||
The icons in the file browser show you when the actual file (white) and the version in the index (blue) are different, and when they are the same!
|
||||
|
||||
[win]
|
||||
|
||||
Good! The index is sometimes also called the "staging area" - it contains exactly what ends up in the next commit when you use `git commit`!
|
||||
|
||||
[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"
|
25
levels/en_EN/index/checkout
Normal file
25
levels/en_EN/index/checkout
Normal file
|
@ -0,0 +1,25 @@
|
|||
title = Checking out files from the index
|
||||
cards = add reset-file 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
|
||||
echo b > b
|
||||
echo c > c
|
||||
git add .
|
||||
git commit -m "Initial commit"
|
||||
echo x > a
|
||||
echo x > b
|
||||
echo x > c
|
||||
git add c
|
||||
|
||||
[win]
|
||||
|
||||
# Remove all changes in your local files!
|
||||
test "$(git diff --name-only | wc -l)" -eq 0
|
51
levels/en_EN/index/compare
Normal file
51
levels/en_EN/index/compare
Normal file
|
@ -0,0 +1,51 @@
|
|||
title = Step by step
|
||||
cards = checkout commit-auto
|
||||
|
||||
[description]
|
||||
|
||||
Welcome to today's lesson! We're going to learn how to make commits with more 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.
|
||||
|
||||
[win]
|
||||
|
||||
# Right! Having each change in its own commit makes it easier to understand what's going on! Let's learn how to do that!
|
||||
git branch --show-current | grep step-by-step
|
||||
|
||||
[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
|
||||
echo "A smoke detector. It's absolutely silent." > smoke_detector
|
||||
|
||||
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]
|
||||
|
||||
# Pick the timeline that's clearer, and make the alarm go off!
|
||||
git show step-by-step:smoke_detector | tail -n 1 | grep -v "absolutely silent"
|
28
levels/en_EN/index/new
Normal file
28
levels/en_EN/index/new
Normal file
|
@ -0,0 +1,28 @@
|
|||
title = Add new files to the index
|
||||
cards = add commit
|
||||
|
||||
[description]
|
||||
|
||||
So far, when we made a commit, we've always recorded the current status of all objects, right?
|
||||
|
||||
But Git allows you to pick which changes you want to put in a commit!
|
||||
|
||||
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 around icons in the file browser!
|
||||
|
||||
Initially, the index is empty. To make a commit that contains a new file, we need to add it!
|
||||
|
||||
[cli]
|
||||
|
||||
You can use tab completion in the terminal! Start typing a filename, then press the tab key to complete its name. This will often save you some time!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "The candle is burning with a blue flame." > candle
|
||||
|
||||
[win]
|
||||
|
||||
# Add the candle.
|
||||
test "$(git diff --cached --name-only)" = "candle" || file -f .git/candle-added && touch .git/candle-added
|
||||
|
||||
# Make a commit.
|
||||
test "$(git ls-tree --name-only HEAD)" = "candle"
|
37
levels/en_EN/index/reset
Normal file
37
levels/en_EN/index/reset
Normal file
|
@ -0,0 +1,37 @@
|
|||
title = Resetting files in the index
|
||||
cards = add reset-file commit
|
||||
|
||||
[description]
|
||||
|
||||
See the dark shadow behind the icons? That's the version of the file in the last commit!
|
||||
|
||||
For example, these candles have been blown out, and that change has been added.
|
||||
|
||||
But you decide that this was a mistake! You only want to blow out the red candle in the next commit!
|
||||
|
||||
If you already have updated the index to a changed file, but want to reset it, you can use `git reset`!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "It's burning!" > red_candle
|
||||
echo "It's burning!" > green_candle
|
||||
echo "It's burning!" > blue_candle
|
||||
git add .
|
||||
git commit -m "The beginning"
|
||||
|
||||
echo "It's been blown out." > red_candle
|
||||
echo "It's been blown out." > green_candle
|
||||
echo "It's been blown out." > blue_candle
|
||||
git add .
|
||||
|
||||
[win]
|
||||
|
||||
# Reset the changes in the green and blue candles!
|
||||
git show :green_candle | grep burning &&
|
||||
git show :blue_candle | grep burning &&
|
||||
git show :red_candle | grep -v burning
|
||||
|
||||
# And make a commit!
|
||||
git show main:green_candle | grep burning &&
|
||||
git show main:blue_candle | grep burning &&
|
||||
git show main:red_candle | grep -v burning
|
24
levels/en_EN/index/rm
Normal file
24
levels/en_EN/index/rm
Normal file
|
@ -0,0 +1,24 @@
|
|||
title = Delete a file in the next commit
|
||||
cards = add reset-file checkout-file rm file-delete 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
|
5
levels/en_EN/index/sequence
Normal file
5
levels/en_EN/index/sequence
Normal file
|
@ -0,0 +1,5 @@
|
|||
compare
|
||||
new
|
||||
change
|
||||
reset
|
||||
steps
|
53
levels/en_EN/index/steps
Normal file
53
levels/en_EN/index/steps
Normal file
|
@ -0,0 +1,53 @@
|
|||
title = Adding changes step by step
|
||||
cards = add reset-file 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 hammer, balancing on its handle." > hammer
|
||||
echo "A bottle, containing a clear liquid." > bottle
|
||||
echo "A white sugar cube." > sugar_cube
|
||||
|
||||
git add .
|
||||
git commit -m "The beginning"
|
||||
|
||||
[win]
|
||||
|
||||
# Make changes to all three objects, to form a logical sequence of events!
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue