finished the mechanism for setting the language

This commit is contained in:
Luca Canali 2021-09-08 17:00:51 +02:00
parent 705cc849c2
commit 50ee071f0e
214 changed files with 94 additions and 10 deletions

View file

@ -0,0 +1,44 @@
title = Creating branches
cards = checkout commit-auto branch branch-delete reset-hard
[description]
You were invited to two parties! At one of them, your favorite band is playing - and the other one is your best friend's birthday party. Where should you go? No worries - as a time travel agent in training, you can go to both parties!
To make it easier to tell which timeline is which, you can create time portals! (We call these "branches".)
[cli]
Branches also make it really easy to travel between different places using the command line! As soon as you have a branch called "birthday", you can type `git checkout birthday` to travel to it!
[setup]
echo "You wrap the birthday present, and grab your concert ticket." > you
git add .
git commit -m "Evening preparations"
echo "You go to the birthday party!" >> you
git add .
git commit -m "Go to the birthday"
git checkout HEAD~1
echo "You go to the concert!" > you
git add .
git commit -m "Go to the concert"
git checkout HEAD~1
git branch -D main
[win]
# Create a branch called 'birthday' that points to the birthday timeline.
git show birthday | grep 'to the birthday'
# Create a branch called 'concert' that points to the concert timeline.
git show concert | grep 'to the concert'
[congrats]
Now you can travel between those branches easily (using `git checkout`) - try it!
Your friend is happy that you made it to the birthday party and you also got your concert ticket signed. Yay!

View file

@ -0,0 +1,47 @@
title = Deleting branches
cards = checkout commit-auto reset-hard branch-delete
[description]
Life is full of dangers, right? Even when walking to school, it seems like there's a lot of risks!
This Monday is especially bad. You made it to school, but there's some timelines you definitely don't want to keep around.
[setup]
echo You leave your house and start walking to school. > you
git add .
git commit -m "Good morning!"
echo You walk on the right side of the street. >> you
git commit -am "Right side"
echo You jump over an manhole in the walkway, and arrive at school on time. >> you
git commit -am "Jump"
git checkout HEAD^ -b friend
echo Suddenly, you fall down, splash into stinking water, and are eaten by an alligator. >> you
git commit -am "A new friend"
git checkout HEAD~2 -b music
echo You walk on the left side of the street. >> you
git commit -am "Left side"
echo Because you\'re kind of late, you start running. Someone throws a piano out of their windows, and it smashes you. >> you
git commit -am "Sounds nice"
git checkout HEAD^ -b ice-cream
echo You\'re not in a hurry, and walk slowly. You even get some ice cream on your way. You arrive at school too late, your teacher is angry, and you are expelled. >> you
git commit -am "Yum"
git branch -M main leap
git checkout leap^^
[win]
# Find the bad branches and delete them. Keep only the best one.
test "$(git show-ref --heads | cut -f2 -d' ')" = "$(echo refs/heads/leap)"
[congrats]
On second thought, maybe you even prefer the ice cream timeline to the main one? :)

View file

@ -0,0 +1,43 @@
title = Moving through time
cards = checkout commit-auto
[description]
The yellow boxes are frozen points in time, we call them "commits"! You can travel between them using the "checkout" card! (Try it!)
Can you find out what happened here? Then, while on the last commit, edit the files to fix the problem, and make a new commit!
[cli]
To checkout a specific commit, type `git checkout`, then a space, and then right click on the commit you want!
This will insert the commit's unique identifier!
[setup]
echo "This piggy bank belongs to the big sister.
It contains 10 coins." > piggy_bank
git add .
git commit -m "The beginning"
echo "A young girl with brown, curly hair." > little_sister
git add .
git commit -m "Little sister comes in"
echo "Has 10 coins." >> little_sister
echo "This piggy bank belongs to the big sister.
It is empty." > piggy_bank
git add .
git commit -m "Little sister does something"
git checkout HEAD^^
git branch -df main
[win]
# Restore sisterly peace.
{ git show HEAD:piggy_bank | grep "10 coins"; } && { git show HEAD:little_sister | grep -v "10 coins"; } && { git rev-parse HEAD^^^; }
[congrats]
Wonderful! Now that you're getting familiar with the time machine, let's look at some more complicated situations...

View file

@ -0,0 +1,65 @@
title = Make parallel commits
cards = checkout commit-auto
[description]
Did you know that creating parallel timelines is perfectly legal and safe? It's true!
Can you find out when things went wrong in this zoo? Then, go back to the last good commit and create a parallel universe where everyone is happy!
[cli]
The blue animal represents a concept known as the "HEAD pointer" in Git: It shows you which commit is the current one.
Here's a cool trick to go to the previous commit:
git checkout HEAD^
You can also go back two commits by typing, for example:
git checkout HEAD~2
[setup]
mkdir cage
echo "Looks very hungry." > cage/lion
echo "A small child.
It really loves cats!" > child
git add .
git commit -m "The beginning"
echo "It's holding a lollipop." >> child
git commit -am "The child buys something"
mv child cage
git add .
git commit -m "The child climbs somewhere"
git rm cage/child
echo "Looks happy. :)" > cage/lion
git add .
git commit -m "Oh no"
echo "It's sleeping." > cage/lion
git add .
git commit -m "Nap time!"
git checkout --detach
git branch -d main
[win]
# Make sure that the child is happy.
git ls-tree --name-only -r HEAD | grep child
# Make sure that the lion gets something to eat.
git show HEAD:cage/lion | grep -v "very hungry"
[congrats]
Whew, good job! This seems like a *much* better outcome.
Feel free to add more parallel timelines, or make them longer.
If you're ready, our next mission is already waiting...

View file

@ -0,0 +1,49 @@
title = Branches grow with you!
cards = checkout commit-auto branch branch-delete reset-hard
[description]
Note that there are two options to "travel to the end of a timeline":
First, you can directly travel to the commit, like we've done it before.
And second, you can travel to the branch label. In this case, when you make a new commit, the branch will grow with you, and still point at the end of the timeline!
[cli]
To travel to a branch, type `git checkout name_of_the_branch`.
And to travel to the last commit, type `git checkout --detach name_of_the_branch`.
[setup]
echo "You wrap the birthday present, and grab your concert ticket." > you
git add .
git commit -m "Evening preparations"
echo "You go to the birthday party!" >> you
git add .
git commit -m "Go to the birthday"
git branch birthday
git checkout HEAD~1
echo "You go to the concert!" > you
git add .
git commit -m "Go to the concert"
git branch concert
git checkout HEAD~1
git branch -D main
[win]
# Travel directly to the last yellow commit of the birthday timeline, make a change to 'you', and make a commit
for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do
if test $(git rev-parse $commit^) = $(git rev-parse birthday); then
return 0
fi
done
return 1
# Travel to the blue 'concert' branch, make a change to 'you', and a commit.
git show concert^ | grep "Go to the concert"

View file

@ -0,0 +1,89 @@
title = Moving branches around
cards = checkout commit-auto merge reset-hard
[description]
One of your colleagues messed up here, and put the branches in the wrong timelines!
You could delete and re-create these branches - but you can also directly move them to different commits, by using
git checkout
on the branch names, and then using
git reset --hard
on the commit where you want the branch to be.
The donut branch is in the right place, but the timeline is still incomplete - make you actually *eat* the donut in that branch!
[setup]
echo "You do not have a baguette.
You do not have coffee.
You do not have a donut." > you
git add .
git commit -m "The Beginning"
git checkout -b coffee
echo "You have a baguette.
You do not have coffee.
You do not have a donut." > you
git add .
git commit -m "You buy a baguette"
echo "You ate a baguette.
You do not have coffee.
You do not have a donut." > you
git add .
git commit -m "You eat the baguette"
git checkout -b baguette main
echo "You do not have a baguette.
You have coffee.
You do not have a donut." > you
git add .
git commit -m "You buy some coffee"
echo "You do not have a baguette.
You drank coffee.
You do not have a donut." > you
git add .
git commit -m "You drink the coffee"
git checkout -b donut main
echo "You do not have a baguette.
You do not have coffee.
You have a donut." > you
git add .
git commit -m "You buy a donut"
git checkout --detach main
[win]
# Did you eat a baguette on the baguette branch?
git show baguette:you | grep "You ate.*baguette"
# Did you drink a coffee on the coffee branch?
git show coffee:you | grep "You drank.*coffee"
# Did you eat a donut on the donut branch?
git show donut:you | grep "You ate.*donut"
[actions]
test "$(git rev-parse HEAD^)" = "$(git rev-parse donut)" && hint "Remember to checkout the blue branch tag when you want it to grow with the timeline."

View file

@ -0,0 +1,6 @@
checkout-commit
fork
branch-create
grow
branch-remove
reorder