Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level: The Truth #277

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gitgud/skills/rampup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'Rampup',
'rampup',
[
BasicLevel("Detaching HEAD", 'detaching', __name__),
BasicLevel("Relative References I: Using (^)", 'relrefs1', __name__),
BasicLevel("Relative References II: Using (~)", 'relrefs2', __name__),
BasicLevel("Reversing Changes in Git", 'reversing', __name__)
Expand Down
18 changes: 0 additions & 18 deletions gitgud/skills/rampup/_detaching/explanation.txt

This file was deleted.

1 change: 0 additions & 1 deletion gitgud/skills/rampup/_detaching/goal.txt

This file was deleted.

5 changes: 0 additions & 5 deletions gitgud/skills/rampup/_detaching/setup.spec

This file was deleted.

4 changes: 0 additions & 4 deletions gitgud/skills/rampup/_detaching/solution.txt

This file was deleted.

5 changes: 0 additions & 5 deletions gitgud/skills/rampup/_detaching/test.spec

This file was deleted.

1 change: 1 addition & 0 deletions gitgud/skills/rewriting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def status(self):
'Rewriting History',
'rewriting',
[
SentenceLevel('The Truth', 'truth', __name__)
]
)
10 changes: 10 additions & 0 deletions gitgud/skills/rewriting/_truth/details.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'1':
message: This
'2':
message: is
'3':
message: an
'4':
message: easy
'5':
message: level
42 changes: 42 additions & 0 deletions gitgud/skills/rewriting/_truth/explanation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
There's something you need to know about...
>>>
The truth is...
>>>
What you did with "git rebase -i"...
>>>
Can be done by...
>>>
Detatching your head! Eek!
>>>
Let me clarify, I'm actually talking about your HEAD.
>>>
HEAD is used to refer to the commit or branch that is currently checked out.
This basically means that when you're on branch master, HEAD means master, which itself means a commit.
benthayer marked this conversation as resolved.
Show resolved Hide resolved
>>>
This is important because when you're in a 'detached HEAD' state, cherry-picking still works the same way, and you can do exactly what you just did in the last level.
>>>
Normally, HEAD points to the branch that you have checked out, so it refers to whichever commit the branch does, even if there is a new commit!
For example, if you have bugFix checked out, then when bugFix is updated, HEAD is updated as well, just like this:

HEAD -> bugFix -> C1 // HEAD points to bugFix.
HEAD -> bugFix -> C2 // A commit moved bugFix to C2, HEAD effectively points to C2
benthayer marked this conversation as resolved.
Show resolved Hide resolved

For us, since no branches point to the first commit, we can't check it out while staying on a branch.
>>>
What if we HEAD to point at a commit rather than a branch?
(e.g., HEAD -> C1 instead of HEAD -> bugFix -> C1)
benthayer marked this conversation as resolved.
Show resolved Hide resolved
>>>
In comes the concept of the 'detached HEAD' state. Simply use "git checkout <commit_hash>" to modify HEAD so that it points to the commit instead of the branch.
>>>
As you've seen, a commit hash is a unique identifier for a commit.
Use "git log" or "git gud status" to see the commit tree and to look for the hashes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also mention git gud show tree

>>>
The hashes look something like: "d6ba740".
The full commit hash is 40 characters long, and every one is unique.
>>>
In general, if you only have a few commits, even just the first few characters of the commit hash are going to be unique, so you can use as few as the first four characters to refer to the commit.
Using the example has above "git checkout d6ba" will detach the HEAD so it refers to the commit with the hash "d6ba740"
>>>
Finally, to beat this level, you're going to need to check out the first commit (detaching HEAD) then cherry-pick the rest of the commits so they are in the right order.
Finish the job by making a new branch with the re-ordered commits.
It can be named anything, but don't check it out so we know you detached your HEAD!
3 changes: 3 additions & 0 deletions gitgud/skills/rewriting/_truth/goal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Just like last level, make the log messages form the sentence "This is an easy level"
This time, instead of rebasing, detach HEAD using git checkout then use git cherry-pick.
Save your changes on a new branch named whatever you want, but don't check it out.
6 changes: 6 additions & 0 deletions gitgud/skills/rewriting/_truth/setup.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1
4
3
2
5 (master)
master
7 changes: 7 additions & 0 deletions gitgud/skills/rewriting/_truth/solution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
git checkout master~4
git cherry-pick master~1
git cherry-pick master~2
git cherry-pick master~3
git cherry-pick master
git branch -D master
git checkout -b master
6 changes: 6 additions & 0 deletions gitgud/skills/rewriting/_truth/test.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1
2'
3'
4'
5' (master)
master
6 changes: 3 additions & 3 deletions gitgud/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def test_load(gg):
load_tests = [
('git gud load 1', all_skills["1"]["1"]),
('git gud load rampup', all_skills["rampup"]["1"]),
('git gud load 2 detaching', all_skills["2"]["detaching"]),
('git gud load rampup 4', all_skills["rampup"]["4"]),
('git gud load 2 relrefs1', all_skills["2"]["relrefs1"]),
('git gud load rampup 3', all_skills["rampup"]["3"]),
('git gud load 5-octopus', all_skills["5"]["octopus"]),
('git gud load rampup-4', all_skills["rampup"]["4"]),
('git gud load rampup-3', all_skills["rampup"]["3"]),
('git gud load -2', all_skills["rampup"]["2"])
]

Expand Down