0

I have worked on a feature-branch, and I have sent a merge request with the following commits

feature-branch: A - B

Someone accepted it by mistake, without reviewing it and it was merged in master.

That same person applied a revert commits of the feature commits on master.

master: A - B- C (revert b) - D (revert a)

I kept working and added a new commit with some minor details in feature-branch

feature-branch: A - B - E

How do I send a merge request with all the changes? including those that were removed in the revert

I have tried following this but it didn't work for me

In feature branch

$ git cherry-pick -x C
$ git cherry-pick -x D

The result:

 feature-branch: A - B - E - F (revert b) - G (revert a)

Then I applied

$ git revert G
$ git revert F

The result:

 feature-branch: A - B - E - F (revert b) - G (revert a) - H (revert g) - I (revert f)

Now, when resubmitting merge request from my feature-branch, I only see the changes made in the last commit as difference to master. But I see all "reverts" commits in the commits detail.

user60108
  • 3,270
  • 2
  • 27
  • 43
  • Just revert the revert as a new commit as part of your new branch from which you make an MR or PR (depending on GitLab or GitHub or Bitbucket). – torek Mar 31 '22 at 00:41
  • I have to create a new branch? I kept working and creating commits in the same branch, without knowing that this had happened – user60108 Mar 31 '22 at 00:46
  • 1
    No, you just have to create a new *commit*. But it will be easier for you if you start with a new branch. (You can then cherry-pick the original commits instead of reverting the revert, if you prefer.) – torek Mar 31 '22 at 00:47
  • thanks, but I want to learn how to fix this with git, we are supposed to use git to be able to handle these cases, otherwise I would use folders. – user60108 Mar 31 '22 at 00:50
  • A new branch or a new commit *is* "with Git". – torek Mar 31 '22 at 00:50
  • But do I have to carry all the changes manually? – user60108 Mar 31 '22 at 00:52
  • 1
    If it were me, I'd start a new branch name at the tip commit for wherever you intend to merge, then use `git cherry-pick` as appropriate to copy all the desired commits to the new branch, e.g., `git cherry-pick ..old-branch` where `` is a commit *not* to copy, from before the point of all the commits that you would like to copy. There will probably be some merge conflicts to resolve to complete this part, and then you're ready to keep working, or `rebase -i`, or make an MR, or whatever. – torek Mar 31 '22 at 00:56
  • I've done git cherry-pick -X of the commits I want to push. When sending the merge request, it shows them in the commit history with their respective changes, but it does not show the difference changes in the diff – user60108 Mar 31 '22 at 14:04
  • That's likely an artifact of whatever software you (or they, whoever your hosting site is) are using to *display* these things. Since you use the term "MR" I'm guessing GitLab, and I have not used GitLab myself. – torek Mar 31 '22 at 18:34

0 Answers0