1

Current scenario:

  • Developer 1 has done some work and pushed to master and deployed.
  • Developer 2 has done some work while developer 1 was working on his own tasks, pushed to master, and didn't deploy yet.

The catch: Developer 2's work would break production if deployed.

So in BitBucket, it looks kinda like this:

31 jan merge dev2 branch into master
31 Jan commit_hash_for_dev2
25 jan commit hash_for_dev2
21 jan commit hash_for_dev1 (currently what is in production)
15 jan commit hash_for_dev2
12 jan commit hash_for_dev2

Do I do:

git checkout hash_for_dev1 . (where the dot makes it the head)
git commit -m "reverting dev2 changes)
git push origin master
open a pull request

How do I bring the master branch head to dev1 latest commit and ignore everything dev2 merged ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
stacknoob
  • 49
  • 7

1 Answers1

1

The idea would be to use git revert, in order to revert a range of commit

git revert -m 1 OLDER_COMMIT^..NEWER_COMMIT

That would create a new commit, with the negative image of dev2 most recent commits.
You can push that and make a pull request.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Interesting, but what if there were multiple commits ? – stacknoob Jan 31 '22 at 23:25
  • Range of commits means multiple commits. Or did you mean multiple ranges? That would imply multiple reverts, from the oldest range to the most recent one. – VonC Jan 31 '22 at 23:29
  • I tried that but got this mainline was specified but commit 33esdfdw3... is not a merge – stacknoob Feb 07 '22 at 15:28
  • @stacknoob Then try without `-m 1`. – VonC Feb 07 '22 at 15:33
  • That won't work because one of the commits is a merge. It goes like this: 1(newest commit - merge), 2 (regular commit), 3 (regular commit), 4 (oldest commit - merge). And I am trying to revert 1 to 4 – stacknoob Feb 07 '22 at 15:49
  • @stacknoob So maybe try to revert first the oldest commit, using `-m1`, then revert the other ones, without `-m 1`. – VonC Feb 07 '22 at 18:31