0

I am trying to revert a range of commits where some commits are merge commits. I need the branch in exact copy before these range of "bad" commits (for example, last good commit is "A")

git revert B1^..B10

If some are merge commits, it will return error something like "...not allowed due to a merge but no -m option was given".

If I provide the option -m 1, it will revert but I am not getting the correct revision of code exactly the same if I checkout commit ID "A".

Note, I do want to keep history so using the reset command is not an option.

alltej
  • 6,787
  • 10
  • 46
  • 87
  • This looks relevant: https://stackoverflow.com/questions/47811491/git-revert-range-of-commits-already-pushed-with-merge-commits-in-between – Tim Biegeleisen Sep 17 '20 at 16:24

2 Answers2

2

I need the branch in exact copy before these range of "bad" commits (for example, last good commit is "A")

git read-tree -um A
git commit
jthill
  • 55,082
  • 5
  • 77
  • 137
0

If you want to undo the last commit totally from git history, as well as the changes file changes, if you have NOT pushed:

git reset HEAD~1

If you have pushed

git reset HEAD

Martins
  • 110
  • 1
  • 9