1

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

kavy8
  • 11
  • 1
  • Would rebasing the branch – so that each commits gets a new commit hash – help? – knittl Jul 30 '20 at 20:14
  • @knittl, I did try rebasing, but there is a lot of changes, and some files have been changed in multiple commits, and I think It would be easier If I could just duplicate it somehow, and then compare the changes directly using a merge. Another option would be comparing the branches directly at their current states, and then resolving conflicts that way. Which would basically just be a merge I guess? I am not the only one working on this, so lots of stuff I don't know what is needed/not needed from previous commits – kavy8 Jul 30 '20 at 20:22
  • Technically, you don't actually want *no* history: you want, instead, a *different* history. But usually it's easier to revert the revert. See also [Re-doing a reverted merge in Git](https://stackoverflow.com/q/1078146/1256452). – torek Jul 31 '20 at 18:40

1 Answers1

1

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

knittl
  • 246,190
  • 53
  • 318
  • 364
  • I think this would have worked tbh. that makes sense and is exactly what I was trying to do I think. I ended up opening the two branches for comparison in git lense extension for VScode, and manually copying changes over. 2 hours in and maybe almost halfway lol – kavy8 Jul 30 '20 at 21:27
  • the merge_branch commit, what would I type in there? the random looking number that is associated with the commit? – kavy8 Jul 30 '20 at 21:38
  • @kavy8: yes, that would work. Depending on how complicated your git history is, `$(git merge-base your_branch target_branch)` would compute the correct value – knittl Jul 31 '20 at 05:55