From a86fcaadbb5536eed665402a8c96c62fe4db259f Mon Sep 17 00:00:00 2001 From: blinry Date: Thu, 4 Feb 2021 12:01:58 +0100 Subject: [PATCH] More polish for the index level --- levels/index/change | 6 ++++++ levels/index/compare | 13 +++++++++---- levels/index/new | 4 +++- levels/index/reset | 35 ++++++++++++++++++++--------------- levels/index/sequence | 1 + levels/index/steps | 10 +++++----- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/levels/index/change b/levels/index/change index e292624..f1e377d 100644 --- a/levels/index/change +++ b/levels/index/change @@ -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 diff --git a/levels/index/compare b/levels/index/compare index 85930aa..e3848a6 100644 --- a/levels/index/compare +++ b/levels/index/compare @@ -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" diff --git a/levels/index/new b/levels/index/new index 434be11..a460dc3 100644 --- a/levels/index/new +++ b/levels/index/new @@ -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 diff --git a/levels/index/reset b/levels/index/reset index ea47c33..5e21973 100644 --- a/levels/index/reset +++ b/levels/index/reset @@ -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 diff --git a/levels/index/sequence b/levels/index/sequence index cf794ab..42f7f48 100644 --- a/levels/index/sequence +++ b/levels/index/sequence @@ -1,4 +1,5 @@ compare new change +reset steps diff --git a/levels/index/steps b/levels/index/steps index 39abf7e..36e7500 100644 --- a/levels/index/steps +++ b/levels/index/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!