0

In my git master branch history something like this has happened.

Assume I have progressed up-to a point (A). And I added some commits (say B, C and D) which was merged from another branch.

(A)--(B)--(C)--(D)

Then I understood that I don't want to add them now for some reason and I reverted those. So now,

(A)--(B)--(C)--(D)--(-D)--(-C)--(-B)

Then I have added some other commits. Assume (E), (F), (G).

(A)--(B)--(C)--(D)--(-D)--(-C)--(-B)--(E)--(F)--(G)

Now, I suddenly want that commits (B, C, D) to be merged via that older branch. So that finally it looks,

(A)--(B)--(C)--(D)--(-D)--(-C)--(-B)--(E)--(F)--(G)--(B)--(C)--(D)

But just because it already has the commits (B, C, D) in history, I can't do that. Can someone please tell me that what is the ideal solution here.??

Please don't ask me to revert the reverts or undo the past that I cannot.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
  • Can't you just cherry-pick the older commits (B, C, D) back onto the current branch? Or is that not working for you? – Ajedi32 Sep 14 '16 at 14:37
  • @Ajedi32 though I mentioned them as B, C, D there are very large number of commits (not 3). So It won't work for me anyway. And also It should raise the same problem right? since they are in history? – Supun Wijerathne Sep 14 '16 at 14:44
  • What did you try before to restore the commits? Anyway, you reverted each commit before with `git revert`, so why is cherry-picking to get them back particularly burdensome? – Ajedi32 Sep 14 '16 at 14:53
  • 2
    @Ajedi32 actually I reverted the merges, not commits, but I can't cherry-pick merges right? Can I? I just tried merging. :)) – Supun Wijerathne Sep 14 '16 at 15:01
  • 1
    In that case: Possible duplicate of [Re-doing a reverted merge in Git](http://stackoverflow.com/questions/1078146/re-doing-a-reverted-merge-in-git) – Ajedi32 Sep 14 '16 at 15:13
  • @Ajedi32 I also found that.. but it is asking to revert the reverts. :// – Supun Wijerathne Sep 14 '16 at 15:19
  • Why can't you revert the reverts? If `H` is the original merge, and `I` is the revert of that merge, is there a reason you can't create commit `J` that is a revert of `I`? – Scott Weldon Sep 14 '16 at 17:22
  • @ScottWeldon definitely I can do.. But it shows my work as reverts in the history right.. not commits.. I want my work to show in history as commits.. not reverts.. to appear it nice. :)) if there's no solution for that.. I definitely go for reverting the reverts. :)) – Supun Wijerathne Sep 15 '16 at 01:20
  • Well the original commits (`B`, `C`, and `D`) will still be in the history either way, and AFAIK, the only difference between a revert and a normal commit is Git adds e.g. `Reverts commit aaaabb` to the commit message (and you can edit that). So in the scenario I gave, there shouldn't much difference between commit `J` being (1) a revert of `I` which is a revert of the merge `H`, or (2) a new merge commit from your branch. – Scott Weldon Sep 15 '16 at 16:34
  • If you'd still like to try a new merge: what was the error you got when you tried to merge? You said you can't do that, but why is that? Also relevant: are you merging with `--ff-only` or `--no-ff`? – Scott Weldon Sep 15 '16 at 16:36

0 Answers0