Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebase on the root and keep empty commits

Tags:

git

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.

like image 795
eush77 Avatar asked Dec 30 '15 12:12

eush77


People also ask

Is commit required after rebase?

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.

Does rebase create new commits?

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.

Does rebase preserving merge commits?

Merge-preserving rebase is willing to replay (some) merge commits, whereas normal rebase completely ignores merge commits.

What does git rebase -- root do?

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.


1 Answers

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:

  • Why is git rebase discarding my commits?
  • Why is "rebase --onto ABC" different than "rebase ABC"?
like image 109
petrpulc Avatar answered Nov 15 '22 23:11

petrpulc