mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-20 20:33:11 +01:00
More polish for the index level
This commit is contained in:
parent
4f4857bdf6
commit
a86fcaadbb
6 changed files with 44 additions and 25 deletions
|
@ -7,6 +7,12 @@ When we change files, the index won't change on its own. We have to use `git add
|
|||
|
||||
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
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
title = Step by step
|
||||
cards = checkout
|
||||
cards = checkout commit-auto
|
||||
|
||||
[description]
|
||||
|
||||
Welcome to today's lesson! Today, we're going to learn how to make commits with precision!
|
||||
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!
|
||||
|
||||
[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"
|
||||
|
@ -41,5 +46,5 @@ git checkout HEAD~3
|
|||
|
||||
[win]
|
||||
|
||||
# This level doesn't have a goal yet.
|
||||
false
|
||||
# Pick the timeline that's clearer, and make the next logical change!
|
||||
git show step-by-step:smoke_detector | grep -v "absolutely silent"
|
||||
|
|
|
@ -3,12 +3,14 @@ cards = add commit
|
|||
|
||||
[description]
|
||||
|
||||
So far, when we made a commit, we've always recorded the current status all objects, right?
|
||||
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!
|
||||
|
||||
Initially, the index is empty. To make a commit that contains a new file, we need to add it!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "The candle is burning with a blue flame." > candle
|
||||
|
|
|
@ -3,30 +3,35 @@ cards = add reset-file commit
|
|||
|
||||
[description]
|
||||
|
||||
See the dark shadow behind the icons? That's the version of the commit you're at!
|
||||
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 a > a
|
||||
echo b > b
|
||||
echo c > c
|
||||
echo "It's burning!" > red_candle
|
||||
echo "It's burning!" > green_candle
|
||||
echo "It's burning!" > blue_candle
|
||||
git add .
|
||||
git commit -m "Initial commit"
|
||||
echo x > a
|
||||
echo x > b
|
||||
echo x > c
|
||||
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 a and c
|
||||
test "$(git show :a)" == "a" &&
|
||||
test "$(git show :b)" != "a" &&
|
||||
test "$(git show :c)" == "c"
|
||||
# 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!
|
||||
test "$(git show main:a)" == "a" &&
|
||||
test "$(git show main:b)" != "b" &&
|
||||
test "$(git show main:c)" == "c"
|
||||
git show main:green_candle | grep burning &&
|
||||
git show main:blue_candle | grep burning &&
|
||||
git show main:red_candle | grep -v burning
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
compare
|
||||
new
|
||||
change
|
||||
reset
|
||||
steps
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
title = Adding changes step by step
|
||||
cards = add commit
|
||||
cards = add reset-file commit
|
||||
|
||||
[description]
|
||||
|
||||
|
@ -7,16 +7,16 @@ The index is really useful, because it allows us to be precise about which chang
|
|||
|
||||
[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
|
||||
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!
|
||||
# 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!
|
||||
|
|
Loading…
Reference in a new issue