How can I rebase local branch into origin without merging?

85 Views Asked by At

I have the following case

o--A--B--C <-origin/master
 \-D--E <-master

I would like to achieve the following

o--A--B--C--D--E <-origin/master

and also keeping the tags at D and E.

If I do a rebase then the D and E would be merged resulting D' and E'

o--A--B--C--D'--E' <-origin/master

Also the tags would not be moved and still pointing to hash of commit D and E.

Update 1

If I have file A.txt at C and file B.txt at D, the rebase will keep both A.txt and B.txt at commit D'. How can I do a rebase but preserve all the file structure and content what I had at D.?

2

There are 2 best solutions below

0
On

If nodes D and E have tags, they will not be moved with the rebase. D and E are placeholder names for hashes, and are not git tags.

I think you may have been using the word tag incorrectly, or in a casual sense. But a git tag is exactly what you want.

2
On

First lets agree on what merge means. You wrote:

If I do a rebase then the D and E would be merged resulting D' and E'...

Instead of the word merged there, it makes more sense to say replayed. An actual merge in your case results in a new commit with two parents (from each branch).

There is no way to rebase and keep D and E commit IDs intact.

You must choose either rebase or merge. If you rebase, your commit IDs will change, and then you can make new tags for D' and E' (and perhaps discard your previous tags for D and E).

If you merge, the commit IDs for D and E will remain intact and you can use your existing tags, but you will have a merge commit and your history will not be in a straight line.