You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The book does not explain how to select the correct SHA1 commit to start a rebase operation on. The book has no example for the git rebase -i [sha1 of specific commit] command.
Following on from my git rebase headaches from #1244
@ben seems to have a nice workflow, maybe we should try adding that into the book? It skips figuring out the correct SHA1 hash to start from atleast... 😄
The other way you'd do a rebase looks like this, which sounds like a lot but isn't that bad once you've done it 3 or so times:
1. Fetch from the remote that represents this repo (`git fetch upstream`)
2. Start an interactive rebase on the newly-fetched master (`git rebase -i upstream/master`)
3. In the resulting editor, change every occurrence of `pick` _except the first_ to `fixup` (or `f`)
4. Change the first `pick` to `reword` (or `r`)
5. `:wq`
6. The next editor is for the final commit message. Change the contents to something reasonable and `:wq`
Again, that sounds hard, but if you've done it before it's not so bad, and the results are rather nice.
For example, if you want to change the last three commit messages, or any of the commit messages in that group, you supply as an argument to git rebase -i the parent of the last commit you want to edit, which is HEAD~2^ or HEAD~3.
It may be easier to remember the ~3 because you’re trying to edit the last three commits, but keep in mind that you’re actually designating four commits ago, the parent of the last commit you want to edit:
$ git rebase -i HEAD~3
I put in bold the information about the commit you must provide to the git rebase -i command.
You simply must pass the parent of the commit you want rebase from. Is not it clear enough?
Thanks for responding. 😄 I've chunked this comment into separate sections, I hope this is readable for you.
Executive summary of proposed changes:
Add the git rebase -i command from the git manual.
Add text that clearly explains "parent of commit".
Add a sane, "batteries included" workflow for rebasing, with clear examples/guides.
Now I know this is getting way outside of the "one clear, actionable bug per report" territory.
Do you want me to file 2 new issues (for point 2 and 3 of the list above)? And continue the conversation in their respective issues?
On git rebase command:
Current text:
"you supply as an argument to git rebase -i the parent of the last commit you want to edit,":
I need to know what a "argument" to a command is. (this is not a really big deal, but it's programmer language, instead of normal people language)
Command to use: git rebase -i
"the parent of the last commit you want to edit", this is a lot to unpack in just a few words.
I still don't know where to start rebasing from. 😕
The current text only has a fully explained example for git rebase -i HEAD~3 usage.
Git manual explanation:
Start it with the last commit you want to retain as-is: git rebase -i <after-this-commit>
How to pick the right commit to start from.
Command to use git rebase -ibut also the argument <after-this-commit>, so it's more specific.
I might actually succeed following that instruction. 😄
On parent of a commit terminology in the Pro Git book:
I've tried searching for parent in the progit2/master source, and I'm not really finding anything, that to me, explains definitively how parent/child works in git. I think the most relevant hits of parent are:
These links all contain the word "parent" https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
When you make a commit, Git stores a commit object that contains a pointer to the snapshot of the content you staged. This object also contains the author’s name and email address, the message that you typed, and pointers to the commit or commits that directly came before this commit (its parent or parents): zero parents for the initial commit, one parent for a normal commit, and multiple parents for a commit that results from a merge of two or more branches.
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent.
The -m 1 flag indicates which parent is the “mainline” and should be kept. When you invoke a merge into HEAD (git merge topic), the new commit has two parents: the first one is HEAD (C6), and the second is the tip of the branch being merged in (C4). In this case, we want to undo all the changes introduced by merging in parent #2 (C4), while keeping all the content from parent #1 (C6).
On including a sane workflow:
Now that the whole "specific git commit to use for rebase" and "parent terminology" has been covered. I would like to propose that the book include a workflow that skips that whole "select correct sha1" process altogether. I'm looking for some "batteries included" workflows so to speak.
I hope I'm not the only one struggling with the git rebase workflow, and I hope that improving the book with some workflows helps other readers too. 👍
Activity
HonkingGoose commentedon Apr 15, 2019
Following on from my git rebase headaches from #1244
@ben seems to have a nice workflow, maybe we should try adding that into the book? It skips figuring out the correct SHA1 hash to start from atleast... 😄
Ben's workflow:
aollier commentedon Apr 16, 2019
From https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History:
I put in bold the information about the commit you must provide to the
git rebase -icommand.You simply must pass the parent of the commit you want rebase from. Is not it clear enough?
HonkingGoose commentedon Apr 16, 2019
Hi @aollier,
Thanks for responding. 😄 I've chunked this comment into separate sections, I hope this is readable for you.
Executive summary of proposed changes:
Now I know this is getting way outside of the "one clear, actionable bug per report" territory.
Do you want me to file 2 new issues (for point 2 and 3 of the list above)? And continue the conversation in their respective issues?
On git rebase command:
Current text:
git rebase -iThe current text only has a fully explained example for
git rebase -i HEAD~3usage.Git manual explanation:
git rebase -ibut also the argument<after-this-commit>, so it's more specific.On parent of a commit terminology in the Pro Git book:
I've tried searching for
parentin theprogit2/mastersource, and I'm not really finding anything, that to me, explains definitively how parent/child works in git. I think the most relevant hits ofparentare:These links all contain the word "parent"
https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging
On including a sane workflow:
Now that the whole "specific git commit to use for rebase" and "parent terminology" has been covered. I would like to propose that the book include a workflow that skips that whole "select correct sha1" process altogether. I'm looking for some "batteries included" workflows so to speak.
I hope I'm not the only one struggling with the git rebase workflow, and I hope that improving the book with some workflows helps other readers too. 👍
Thank you for your time, and for reading this.