Re: why does "git revert" commit even if i try to bail with ":q!"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 12, 2019 at 11:14 AM Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
>
> On Tue, 12 Mar 2019, Bryan Turner wrote:
>
> > On Tue, Mar 12, 2019 at 10:23 AM Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
> > >
> > >   never noticed this before ... when i do a regular "git commit" and
> > > enter my "vi" edit session and change my mind, i can bail with ":q!",
> > > regardless of what i've set up as a commit message, and i'll see:
> > >
> > >   Aborting commit due to empty commit message.
> > >
> > > however, i was just playing with "git revert" and, after i ran:
> > >
> > >   $ git revert <commit SHA>
> > >
> > >   again, simulating that i changed my mind, i just typed ":q!", but
> > > the revert went ahead, anyway. i tried again, this time completely
> > > deleting all the lines from the commit msg (as the template
> > > suggested), but the revert *still* completed after typing ":q!".
> > >
> > >   it was only after deleting all the lines and using ":wq" that the
> > > revert was cancelled:
> > >
> > >   Aborting commit due to empty commit message.
> > >
> > > that seems ... inconsistent. am i misunderstanding something?
>
> ... snip ...
>
> > When you use git revert, though, it writes a valid, usable message
> > to the file ("Revert <subject>\n\nThis reverts commit <sha>"). When
> > you :q!, that's still in the file. Since the file isn't empty, the
> > commit moves ahead.
>
>   again, this is also not true. as i think i mentioned in my earlier
> note, if you get dropped into the revert edit session, even if you
> delete all the usable commit message lines, if you type ":q!", the
> revert commit still succeeds and, in fact, with all of the
> revert-supplied usable lines that you just finished removing.

Again, unless you :w and _write_ deleting the lines, the file that Git
sees still has the default message it generated. So, delete all the
lines, then :w to write that change, and then, as a separate
operation, do :q!. It won't commit the revert.

Hope this helps,
Bryan



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux