-
Notifications
You must be signed in to change notification settings - Fork 53
Level: The Truth #277
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
base: main
Are you sure you want to change the base?
Level: The Truth #277
Changes from 1 commit
a3c9704
9c502a0
45a1031
dceca84
f68c1c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,42 @@ | ||
| You've already seen some of the stuff "git rebase -i" can do. | ||
| "git rebase -i" can also be used to reoder commits. | ||
| There's something you need to know about... | ||
| >>> | ||
| When the editor opens, simply re-order the commits to be in the order you want them to be in. | ||
| On a technical level, Git is changing the parent of each of the commits. The order of the commits is determined by looking at the parents of each commit. | ||
| The truth is... | ||
| >>> | ||
| For this level, each commit has a single word message that are meant to come together to form the sentence "This is an easy level" when viewing them in chronological order. You are meant to put the commits in order and form that sentence. | ||
| What you did with "git rebase -i"... | ||
| >>> | ||
| You can see the commits in chronological order by running "git log --reversed". | ||
| Git normally tries to show you the most recent commit first since that's normally more useful. That's why you need the "--reversed" flag | ||
| Can be done by... | ||
| >>> | ||
| Run "git rebase -i <commit>" for more details. It contains useful information | ||
| 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. | ||
| >>> | ||
| 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.
Outdated
|
||
|
|
||
| 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.
Outdated
|
||
| >>> | ||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also mention |
||
| >>> | ||
| 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! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| Using git rebase -i, make the log messages form the sentence "This is an easy level" | ||
| 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. |
Uh oh!
There was an error while loading. Please reload this page.