Suppose I have a branch that consists of three commits, one of them empty:
# On branch test
3208910 empty
85c949c bar
0c1a615 foo
I want to rebase it on the root and from the man page it seems that --root --keep-empty
is exactly what I need.
However, both git rebase -i --root
and git rebase -i --root --keep-empty
omit the empty commit and show me this plan instead:
pick 0c1a615 foo
pick 85c949c bar
How can I rebase the entire branch and keep empty commits at the same time?
P.S. I needed this to remove a few first commits on the branch and I managed to achieve that with filter-branch
as described in this SO answer, but I'm still interested in knowing if rebase
is capable of that. Is it a bug in Git that I found? It's hard to believe this behavior is intentional but I'm not sure.
P.P.S. I found that I can edit the plan by hand and add pick 3208910
.
The purpose of rebase is make your commits look as if they were changes to the branch you rebase onto. So the most logical way is to incorporate merge conflicts into these commits. No additional commits is required thus.
The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.
Merge-preserving rebase is willing to replay (some) merge commits, whereas normal rebase completely ignores merge commits.
Rebase all commits reachable from <branch> , instead of limiting them with an <upstream> . This allows you to rebase the root commit(s) on a branch. When used with --onto , it will skip changes already contained in <newbase> (instead of <upstream> ) whereas without --onto it will operate on every change.
It is connected with the two modes of git rebase
.
Patch-id approach should keep the empty commit and is the default behaviour.
However, as correctly pinpointed, --root
flag is a shortcut for "onto NULL" and this triggers the fork-point mode.
More information can be deducted from:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With