mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-13 19:04:54 +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!
|
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]
|
[setup]
|
||||||
|
|
||||||
echo "The candle is burning with a blue flame." > candle
|
echo "The candle is burning with a blue flame." > candle
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
title = Step by step
|
title = Step by step
|
||||||
cards = checkout
|
cards = checkout commit-auto
|
||||||
|
|
||||||
[description]
|
[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.
|
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]
|
[setup]
|
||||||
|
|
||||||
echo "A small, but heavy glass ball." > ball
|
echo "A small, but heavy glass ball." > ball
|
||||||
echo "A thin book, that's standing upright." > book
|
echo "A thin book, that's standing upright." > book
|
||||||
echo "A candle, burning with a blue flame." > candle
|
echo "A candle, burning with a blue flame." > candle
|
||||||
|
echo "A smoke detector. It's absolutely silent." > smoke_detector
|
||||||
|
|
||||||
git add .
|
git add .
|
||||||
git commit -m "The beginning"
|
git commit -m "The beginning"
|
||||||
|
@ -41,5 +46,5 @@ git checkout HEAD~3
|
||||||
|
|
||||||
[win]
|
[win]
|
||||||
|
|
||||||
# This level doesn't have a goal yet.
|
# Pick the timeline that's clearer, and make the next logical change!
|
||||||
false
|
git show step-by-step:smoke_detector | grep -v "absolutely silent"
|
||||||
|
|
|
@ -3,12 +3,14 @@ cards = add commit
|
||||||
|
|
||||||
[description]
|
[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!
|
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!
|
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]
|
[setup]
|
||||||
|
|
||||||
echo "The candle is burning with a blue flame." > candle
|
echo "The candle is burning with a blue flame." > candle
|
||||||
|
|
|
@ -3,30 +3,35 @@ cards = add reset-file commit
|
||||||
|
|
||||||
[description]
|
[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`!
|
If you already have updated the index to a changed file, but want to reset it, you can use `git reset`!
|
||||||
|
|
||||||
[setup]
|
[setup]
|
||||||
|
|
||||||
echo a > a
|
echo "It's burning!" > red_candle
|
||||||
echo b > b
|
echo "It's burning!" > green_candle
|
||||||
echo c > c
|
echo "It's burning!" > blue_candle
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Initial commit"
|
git commit -m "The beginning"
|
||||||
echo x > a
|
|
||||||
echo x > b
|
echo "It's been blown out." > red_candle
|
||||||
echo x > c
|
echo "It's been blown out." > green_candle
|
||||||
|
echo "It's been blown out." > blue_candle
|
||||||
git add .
|
git add .
|
||||||
|
|
||||||
[win]
|
[win]
|
||||||
|
|
||||||
# Reset the changes in a and c
|
# Reset the changes in the green and blue candles!
|
||||||
test "$(git show :a)" == "a" &&
|
git show :green_candle | grep burning &&
|
||||||
test "$(git show :b)" != "a" &&
|
git show :blue_candle | grep burning &&
|
||||||
test "$(git show :c)" == "c"
|
git show :red_candle | grep -v burning
|
||||||
|
|
||||||
# And make a commit!
|
# And make a commit!
|
||||||
test "$(git show main:a)" == "a" &&
|
git show main:green_candle | grep burning &&
|
||||||
test "$(git show main:b)" != "b" &&
|
git show main:blue_candle | grep burning &&
|
||||||
test "$(git show main:c)" == "c"
|
git show main:red_candle | grep -v burning
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
compare
|
compare
|
||||||
new
|
new
|
||||||
change
|
change
|
||||||
|
reset
|
||||||
steps
|
steps
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
title = Adding changes step by step
|
title = Adding changes step by step
|
||||||
cards = add commit
|
cards = add reset-file commit
|
||||||
|
|
||||||
[description]
|
[description]
|
||||||
|
|
||||||
|
@ -7,16 +7,16 @@ The index is really useful, because it allows us to be precise about which chang
|
||||||
|
|
||||||
[setup]
|
[setup]
|
||||||
|
|
||||||
echo "A small, but heavy glass ball. It is not touching the book." > ball
|
echo "A hammer, balancing on its handle." > hammer
|
||||||
echo "A thin book, that's standing upright." > book
|
echo "A bottle, containing a clear liquid." > bottle
|
||||||
echo "A candle, burning with a blue flame." > candle
|
echo "A white sugar cube." > sugar_cube
|
||||||
|
|
||||||
git add .
|
git add .
|
||||||
git commit -m "The beginning"
|
git commit -m "The beginning"
|
||||||
|
|
||||||
[win]
|
[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
|
test "$(git diff --name-only | wc -l)" -eq 3 || file -f .git/candle-changed && touch .git/candle-changed
|
||||||
|
|
||||||
# Only add one of these changes!
|
# Only add one of these changes!
|
||||||
|
|
Loading…
Reference in a new issue