Rebase git tree keeping revert references

70 Views Asked by At

I have a couple of branches with many commits (~20-30) and some of them revert earlier commits from the same branch.

I now need to rebase those branches on current HEAD but I want to keep the revert commits, at least for now. (The branch is a port from another tree so it is valuable to see what is NOT used) Those commits usually have a message like "This reverts <SHA>" which will become invalid after the rebase.

Is there any option or tool to do the rebase but update the revert commit messages while doing so in a way so that they reference the new (rebased) commits?

Example history:

  • SHA0 Old HEAD
  • SHA1 Add Foo
  • SHA2 Add Bar
  • SHA3 Revert "Add Foo"\n\n This reverts SHA1

Should become:

  • SHA10 New HEAD
  • SHA11 Add Foo
  • SHA12 Add Bar
  • SHA13 Revert "Add Foo"\n\n This reverts SHA11
0

There are 0 best solutions below