oh-my-git/levels/it/changing-the-past/reorder

78 lines
1.7 KiB
Text

title = Reordering events
cards = checkout commit-auto reset-hard rebase-interactive cherry-pick
[description]
Oops, looks like there's something messed up here. Can you put the events back into their correct order?
There are two ways to do this: You can drag the "interactive rebase" card to the commit before the one you want to change, then reorder the lines in the file that opens, and save it.
Or you can reset the main tag to the very first commit, and then cherry-pick single commits in the order you want. You have cards for both approaches!
[setup]
echo "You just woke up.
You are NOT wearing underwear.
You are NOT wearing pants.
You are NOT wearing a shirt.
You are NOT wearing shoes." > you
git add .
git commit -m "The Beginning"
echo "You just woke up.
You are NOT wearing underwear.
You are NOT wearing pants.
You are NOT wearing a shirt.
You are wearing shoes." > you
git commit -am "Put on shoes"
echo "You just woke up.
You are NOT wearing underwear.
You are wearing pants.
You are NOT wearing a shirt.
You are wearing shoes." > you
git commit -am "Put on pants"
echo "You just woke up.
You are wearing underwear.
You are wearing pants.
You are NOT wearing a shirt.
You are wearing shoes." > you
git commit -am "Put on underwear"
echo "You just woke up.
You are wearing underwear.
You are wearing pants.
You are wearing a shirt.
You are wearing shoes." > you
git commit -am "Put on shirt"
[win]
# Reorder the commits to dress yourself in the correct way
{ git log main --oneline | perl -0777 -ne'exit(1) if not /shoes[\s\S]*pants[\s\S]*underwear/'; } && { test "$(git log main --oneline | wc -l)" -eq 5; }
[congrats]
Feel free to reset the level and try the other strategy! Which one do you like better?