0

Say I have two branches A and B, where B is 10 commits ahead of A. Some of the 10 commits are tagged with special_tag.

I want to revert all the commits tagged with special_tag until branch A.

How can I do that?

Simon
  • 325
  • 1
  • 6
  • By "Some of the 10 commits are tagged with special_tag", you mean `special_tag` references some single commit in the history of `B`, right? And you want to create N revert commits, where N is the number of commits in the history of `special_tag` down to `A`? – Brian61354270 Aug 09 '23 at 18:12
  • And to clarify terminology, you want to _revert_ those commits (as in, create new commits that do the opposite of what the original commits did), and not drop them (as in, re-write `B` so that they never existed), correct? – Brian61354270 Aug 09 '23 at 18:13
  • @Brian61354270 Yes, I want to do it as stated in your first comment. As for the second comment, it does not really matter if revert or dropping them. – Simon Aug 09 '23 at 18:17
  • In that case, I think dropping would be simpler. For that, you can just checkout `B` and run `git rebase -i A`. Then just change `pick` to `drop` on the lines for the commits you want to get rid of (or just [delete the those lines](https://stackoverflow.com/q/35846154/11082165) altogether, which might be easier if there's a lot of them) – Brian61354270 Aug 09 '23 at 18:22
  • @Brian61354270 So I have to manually delete the special commits that I want to get rid of? There is no special command for that? – Simon Aug 09 '23 at 18:26
  • Probably no single command. You can automate the rebase using `GIT_SEQUENCE_EDITOR` and some clever shell scripting. But if this is a one-off, it's just doing an interactive rebase would be simplest. See also [Delete a range of commits](https://stackoverflow.com/q/28566734/11082165) and [How do I delete a commit from a branch?](https://stackoverflow.com/q/1338728/11082165) – Brian61354270 Aug 09 '23 at 18:42
  • Actually, after some better googling, something like `git revert A^..special_tag` would probably do the trick – Brian61354270 Aug 09 '23 at 18:43

0 Answers0