2

I find myself in a precarious situation.

I work on refactoring a big, existing codebase. I decided to comment out some tests and enable them gradually as I adapt the code. Unfortunately, I committed the commenting-out and now the git blame history of a complete test module shows me as the author of the last change. My only committed contribution to this code is two commits (commenting and uncommenting) - unfortunately the first ones comes with changes in other places I want to keep.

I am not knowledgeable in git enough to know if there is a relatively easy way to correct the git history to showing the author of the previous state of the code (prior to my commenting out).

Is starting from scratch my only option?

LetsPlayYahtzee
  • 7,161
  • 12
  • 41
  • 65

1 Answers1

2

Modern git blame takes arguments to tell it: don't blame this revision. See the --ignore-rev and --ignore-revs-file options. Your simplest path will be to list your own commits in some file and use --ignore-revs-file.

If your git blame is too old, consider upgrading Git; if that's not possible, note that git blame starts from (and then works backwards from) any specified revision, so you can simply pick some revision before your change.

torek
  • 448,244
  • 59
  • 642
  • 775
  • My impression was that the OP wants the permanent history (not just one invocation of blame) to show the original author as the author, instead of the OP, who only added and removed some comments (in a particular section). Perhaps reverting to the original commit would get that. As for preserving those parts of the new commit that the OP wants to keep, perhaps a selective stash (prior to the revert), followed by a revert, followed by a stash apply, and commit. How does that sound? – Randy Leberknight Aug 29 '21 at 18:15
  • 1
    @RandyLeberknight: Reverting (if you mean `git revert`) won't help: the commits *are* the history, reverting *adds to* the history by adding another commit, and now every line that was touched by the original commit is also touched by the revert (which puts the originals back). Rewriting history to remove the unwanted commit will work, but has the obvious disadvantage that it rewrites history. – torek Aug 30 '21 at 08:27
  • Ah, I see now, I think. If the OP does the revert I suggested, then they are still recorded as the user who made that commit. My mistake. Thanks for clarifying! – Randy Leberknight Aug 31 '21 at 21:36