kavy8
kavy8

Reputation: 11

Duplicate a branch with no history

I made a mistake when reverting a merge, and now when I am trying to re-merge, git is saying everything is up to date, because of the reverted merge. Is there a way to duplicate a branch, but have absolutely no commit history? So that way, I can re-merge and not have to worry about 'everything up to date' ? Thanks

Upvotes: 1

Views: 66

Answers (1)

knittl
knittl

Reputation: 265533

The changes of your commits have already been merged, that's why Git says "already up to date". Reverting creates new changes on top of that. If you need to merge those commits again, you need to create different commits out of them. An easy solution is to force a rebase of the branch, so that each commit gets a new commit hash.

$ git checkout your_branch
$ git rebase -f merge_base
$ git checkout target_branch
$ git merge your_branch

Where merge_base is the commit from which your branch started, in other words the first commit shared between your branch and the target branch

Upvotes: 1

Related Questions