Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase: copy instead of moving

Tags:

git

rebase

My branches are:

o---o  support.2013.16      \       o---o---o---o---o  master                        \                         o---o---o  hotfix/A 

I need to copy hotfix/A to support.2013.16. I'm aware of cherry-picking, but is it possible to do something like

git rebase --onto support.2013.16 master hotfix/A 

but without moving a branch but copying it instead?

like image 883
Vadim Samokhin Avatar asked Oct 31 '13 11:10

Vadim Samokhin


People also ask

Why Git rebase instead of merge?

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. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .

When to use rebase instead of merge?

Reading the official Git manual it states that rebase “reapplies commits on top of another base branch” , whereas merge “joins two or more development histories together” . In other words, the key difference between merge and rebase is that while merge preserves history as it happened, rebase rewrites it .

What does Git rebase actually do?

Rebase is an action in Git that allows you to rewrite commits from one Git branch to another branch. Essentially, Git rebase is deleting commits from one branch and adding them to another.


1 Answers

Git rebase really does copy the original branch to a new one; but because it moves the branch head, it feels like a move rather than a copy. If you used git branch to add an additional branch head to the original branch, you would still have easy access to the original branch after git rebase had made the rebased copy. So in your example

git branch rebased-A hotfix/A git rebase --onto support.2013.16 master rebased-A 

leaves you with

      o---o---o  rebased-A (hotfix/A')      / o---o  support.2013.16      \       o---o---o---o---o  master                        \                         o---o---o  hotfix/A 
like image 158
Wolf Avatar answered Oct 06 '22 13:10

Wolf