News for hackers. Stuff that matters.
Re:Beej's Guide to Git by aidos on Wednesday February 05, 2025 @04:31AM (#42946123)
Not wrong, but since you’re mentioning vim in the context of git, might be worth adding :cq as a way to exit with a non-zero status to prevent git from finishing the commit / operation.
Re:Beej's Guide to Git by usrme on Wednesday February 05, 2025 @07:41AM (#42947682)
This is a fantastic mention! I've been commenting out my commit message lines and then saving as a way to trigger this. Feeling like a caveman...
Re:Beej's Guide to Git by celticninja on Wednesday February 05, 2025 @04:20PM (#42955330)
Guilty as changed your honour
Re:Beej's Guide to Git by malvim on Thursday February 06, 2025 @07:12AM (#42961622)
Guilty as UNchanged*
Re:Beej's Guide to Git by dotancohen on Wednesday February 05, 2025 @09:09AM (#42948679)
I just love nuggets like this. I've been using VIM for 26 years and git for about 15. I never knew about adding c. I've always felt that :q! should exit with a non-zero status code, at least if no :w had been made.
Re:Beej's Guide to Git by ericholscher on Wednesday February 05, 2025 @09:11AM (#42948693)
I usually use :q! which seems to do the same thing
Re:Beej's Guide to Git by alexjm on Wednesday February 05, 2025 @12:41PM (#42952186)
The minor difference is that :q! quits without saving but returns zero as the exit code, but :cq quits with a nonzero exit code. Git interprets the nonzero exit code as "editing failed", following the Unix convention that zero means success. If you didn't save the commit message while working on it, :q! will send the empty template back to Git, which Git is smart enough to not commit. But if you accidentally save your work partway through, :q! will still commit the message you wanted to abandon.
Re:Beej's Guide to Git by sangnoir on Thursday February 06, 2025 @03:31PM (#42966198)
That only works if the edit buffer is blank or only has commented out lines. In other cases, such as when you're trying to cancel a `git commit --amend` that loads up the last commit message in your buffer, :q! will not cancel the commit, but :cq will.
Re:Beej's Guide to Git by beej71 on Wednesday February 05, 2025 @11:11AM (#42950588)
TIL! The funny thing about Vim is that you can have used vi/Vim for 30+ years and still learn new things. I'll add this to the Vim appendix. Cheers!
Re:Beej's Guide to Git by dexzod on Wednesday February 05, 2025 @12:56PM (#42952451)
It is the same with Git
Re:Beej's Guide to Git by agent281 on Wednesday February 05, 2025 @04:32PM (#42955481)
If you have been using git for 30+ years, you need to take me to your time machine. It turns 20 this year.
Re:Beej's Guide to Git by iN7h33nD on Wednesday February 05, 2025 @01:07PM (#42952635)
Interesting I’ve always just deleted the contents of the entire buffer and :wq to cause a failure due to lack of message
Re:Beej's Guide to Git by olalonde on Wednesday February 05, 2025 @03:30PM (#42954667)
Mnemonic to help remember: cancel quit
Re:Beej's Guide to Git by rstuart4133 on Tuesday February 11, 2025 @11:11PM (#43021805)
:cq is useful in a shell loop that compares two directory trees that invokes vim to let you see what's changed in every file that's different. I use it often:

    ((cd /tmp/t; find . -type f -print) | sort | while read f; do cmp -s {/tmp/t,/tmp/t1}/$f || vim -f -d {/tmp/t,/tmp/x1}/$f 0<&9 || break; done) 9<&0
Typing ^C to vim doesn't get you very far, so if you make a mistake causing the loop to return 1000's of files you are in for a bit of pain without :cq. The :cq triggers the break, exiting the loop.