[llvm-dev] Git question about revert

via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 20 11:17:11 PST 2021


> -----Original Message-----
> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Paul C.
> Anagnostopoulos via llvm-dev
> Sent: Wednesday, January 20, 2021 1:36 PM
> To: llvm-dev at lists.llvm.org
> Subject: [llvm-dev] Git question about revert
> 
> This morning I pushed a commit that killed the build, so I reverted it and
> pushed the new commit to fix the build. Then I did another revert to get
> my changes back so I can work on them some more.
> 
> Is it legitimate to use that second revert commit, which was never pushed,
> to do the additional work, changing the title to something reasonable? If
> not, could you explain what I ought to do?

Whatever workflow you do on your own is up to you, really.

Depending on the circumstances, or just my mood, I might do
  git reset HEAD~1
which puts HEAD back to the first revert, but leaves the files in your
working tree as they were after the second revert.  When you're done, 
you can commit them like any other new work.  It's like starting over
just before you did that first commit.

Another option is to leave the second revert commit there, and then any
new changes can be added to it using
  git commit --amend
This takes the usual "commit" options like -a (all modified files).
Another useful one is "-C HEAD" which leaves the commit message unchanged;
normally --amend will pop you into vim (or whatever editor you have set)
to modify the original commit message.  Editing is handy because reviewers
like to see something in the new commit message that says how you fixed
the problem that the first commit caused.

One issue with revert-of-revert is that "git revert" prepends that
"Revert foo" text onto the headline.  Do that too many times and the
entire commit message starts to look like
   Revert "Revert "Revert "Revert "Revert "Revert ...
and I believe I have actually seen one with 6 Reverts, which made the
llvm-commits email subject line pretty useless.  While it might be 
amusing the first time you see it, I don't like it because the *real* 
commit message is obscured.

What I suggest to people is that if they revert a revert, they should
modify the commit message from
    Revert "Revert "my clever patch""
to
    Reapply "my clever patch"
(some people prefer "Reland") or just go back to the original
    my clever patch
which better describes what the commit is actually about.

--paulr


More information about the llvm-dev mailing list