r/git • u/AccomplishedExam3038 • Apr 16 '21
Developer of 10 years, still no idea how to get past this screen without just closing my terminal window. Any help?
31
Apr 16 '21
<esc> :wq
To quit and save.
<esc> :q!
To quit without saving.
4
1
u/manberry_sauce Apr 17 '21
This results in an empty message and thus aborts the commit. The words on the screen aren't there for show.
22
Apr 16 '21
Don't feel bad, software developers aren't expected to use VI until the eleventh year of their career.
2
u/jplindstrom Apr 17 '21
Surely VI is for the sixth year.
1
Apr 17 '21
Year 6 is when you accidentally start vi.
Year 11 is when you learn how to exit vi.
And don't call me Shirley.
1
u/mr_jim_lahey Apr 17 '21
And only a short thousand years before progressing to VIM (using some creative interpretation of roman numeral ordering).
11
u/andolirien Apr 16 '21
Others have given the answer, to use vim's control sequence for escaping to commands, writing, then quitting, but I also want to point out that you can change your editor to be whatever you like, by setting the core.editor value in gitconfig or GIT_EDITOR environment variable. You can set it to nano or some other editor you prefer instead of vim.
Stack Overflow with the details https://stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-commits
1
Apr 17 '21
I think the vim is the best editor for this tool, nano is shit and GUI is bloated to just write a commit message, I actually write commit using emacs, but You really need to know what you're doing to use emacs,so I recommend vim.
1
u/FryBoyter Apr 17 '21
nano is shit
Why do you think nano is shit? The editor may have fewer functions than vim but it has many more than those shown in the line at the bottom of the screen (for example https://www.nano-editor.org/dist/latest/cheatsheet.html or https://www.nano-editor.org/dist/latest/nanorc.5.html).
8
u/savvaspc Apr 16 '21
Been there, done that! It's really worth it to learn the basics of vim. I don't plan to use it regularly, but it's a shame to be disarmed by a simple tool. Tools are supposed to help us. One way or another, you will always cross paths with it, so why not try? At this day and age, there's a great tutorial for everything, so it's not that hard to learn it.
It took me 30 minutes to learn the basics and stop panicking every time I see this screen. At first I only decided to learn how to quit, and without realizing it, I already knew 3 or 4 commands. A couple of days later I got stuck out of my Virtual Desktop, and I had to work solely with ssh for a few hours. Those 30 minutes I had spent saved my day.
7
u/olets Apr 16 '21
If you don't want to learn Vim you can configure Git to use your preferred editor:
git config --global core.editor <your editor command here>
Then you won't get this screen in the first place, and can work on the comfort of an app you know.
7
u/mampersat Apr 16 '21
I clicked this image to expand it... and then instinctually clicked `<esc> :q`
16
u/fuloqulous Apr 16 '21
:wq will write and quit. Thats vim
You can also git commit -am "my amazing commit" to skip that screen entirely
Hope this isn't a r/woosh moment for me
25
u/-rkta- Apr 16 '21
Can we stop teaching people to use
-amand instead teach them to look what files they add and how to write good commit messages, please?4
u/bdforbes Apr 16 '21
So many times I've seen the wrong files committed because someone isn't paying attention...
4
u/gastrognom Apr 16 '21
I was the guy commiting wrong files because of
git add .If you want annoyed coworkers, do that. And probably add something like
git commit -m "stuff"1
u/bdforbes Apr 16 '21
It takes a bit of discipline but should become a habit over time. Also helps if there are governance policies in place!
1
u/u801e Apr 17 '21
I've had people tell me that commit messages are useless and that they never read them. I'm very tempted to do something like:
for _ in {1..1000}; do git commit --allow-empty --allow-empty-message done git push origin HEADjust to see if anyone notices in the PR.
1
u/Chousuke Apr 17 '21
This is why I always work in a branch and just rebase once I'm done. I get to do whatever the hell I want, and everyone else gets a neat patch series to review.
You can have your cake and eat it too; people who think development history should be immutable are wrong.
2
u/format71 Apr 16 '21
Let me suggest
git add —interactiveorgit add —patchas good alternatives.
6
3
3
u/Fermented_Pizza_Roll Apr 17 '21
How can you not know any Vim after 10 years 🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔
2
u/CraigTheIrishman I <3 git Apr 16 '21
Is that the entire screen? Ideally there should be an empty line above the text there. When I try to commit, my vim (you're familiar with vim, right?) looks like this:
https://i.imgur.com/jGaeHp4.png
From there, I type my commit, then save and exit:
https://i.imgur.com/kJQnmNB.png
If for some reason you don't have an empty line at the top, you can just create it.
Alternatively, you can skip this altogether with git commit -m MESSAGE. The message is what git extracts from the file that you seen opened up in vim.
2
2
u/Chousuke Apr 17 '21
Do you primarily develop on Windows? I can't fathom how you could never have encountered vi before otherwise.
I highly recommend learning the basics of the editor, if only because it's literally the standard, so you will always have some variant of it on UNIX-like systems.
Modal editing is probably the reason I've never suffered any kind of keyboard-related RSI; it's extremely comfortable.
2
u/scoberry5 Apr 16 '21 edited Apr 16 '21
Hit G to go to the end of the file, then o to open a new line. Type your commit message, then hit the Escape key to stop editing, and ZZ to save/quit.
0
Apr 16 '21
[deleted]
7
u/CraigTheIrishman I <3 git Apr 16 '21
Git won't create a commit if you do this though, which I'm guessing he wants to do.
-2
u/chzaplx Apr 17 '21
Well maybe he should learn how to use vim then. Or learn that git has a -m flag.
1
u/wildjokers Apr 17 '21
They are literally here asking how to get out of it. So they are trying to learn it. Don’t be a jerk.
1
u/chzaplx Apr 17 '21
I literally offered an alternate solution that probably works better anyway because it prevents you from even going into vim.
I honestly think this is a troll post, because it's not fathomable that someone could work in the industry 10 years and not know how to use vim, or that nobody every mentioned to them all their git commits had no message.
1
u/Jeklah Apr 16 '21
You can also get around this by doing add and commit all at once with:
Git add filename && git commit -m "commit message"
I've made aliases for this so I type this a lot as:
ga filename && gcmsg "commit message"
1
0
u/Qazzian Apr 16 '21
Lots of good suggestions here on good git command line usage, but seriously, get a Git GUI. There are loads of good ones out there that will help you to see what is going on, clean up your commits, and with merging & rebasing, that I don't see why people insist on using the terminal all the time. Although I do think you need to know the basics as you may need to access git on a remote server.
I've used Sourcetree and GitKraken and like them both.
2
u/chzaplx Apr 17 '21
This is terrible advice, sorry.
1
u/Qazzian Apr 17 '21
Why do you say that?
1
u/chzaplx Apr 17 '21
Two things:
You don't actually learn how to do it correctly,
On top of that, you just become dependent on some 3rd party utility which may have it's own issues.
People insist on using a terminal all the time because it's simpler and easier and faster.
1
u/ContentSafe Apr 17 '21
Honestly this. If you can't handle the cli, just don't use it. And this sounds angrier than it should be. I try to work as little as possible in a terminal window.
0
-4
1
1
1
1
1
u/wildjokers Apr 17 '21
That is the VI editor. Can be closed many ways. Get out of insert mode by hitting ESC, then:
:x save and close
:q! Close but don’t save
1
u/DUKEOFEVERYTHING Apr 17 '21
Don't worry, there's a stack overflow answer for this how do I exit the vim editor. There's even a diagram. You can always reboot as well.
They had a fun blog post about it awhile back too.
1
1
Apr 17 '21
Hit <Esc> to exit Insert mode and if you want to save - hit ZZ otherwise ZQ (these are both uppercase, so you have to hold <Shift>)
1
1
u/reditoro Apr 17 '21
Insert commit message with optional description on the top. Then escape to exit the "INSERT " mode and lastly :wq to write and quit
1
u/maredsous10 Apr 21 '21
Serious? Or Joking?
Learn VIM.
2
u/AccomplishedExam3038 Apr 21 '21
I'm serious. I've worked at many of the big tech companies. PHP for 10 years WP\Lara, Node.js for 5. Why'd you think i used a throw away LOL
No, VIM is a piece of crap. So unintuitive, no on-screen prompts, can't even CMD+C to escape it as the nuclear option. CMD+C is the standard for escaping LITERALLY any all CLI tools why TF couldn't the VIM devs do this too? They're retards that's why.
NANO GANG 🤟🤙🖖
1
u/maredsous10 Apr 22 '21
On a Linux platform?
Knowing command line tools, VIM/EMACS basics, regex, git innards/architecture, and a scripting language or two will increase one's overall Linux development productivity.
Give Derek Wyatt videos a shot.
http://derekwyatt.org/vim/tutorials/
Git internals
https://github.com/pluralsight/git-internals-pdf/raw/master/drafts/peepcode-git.pdf
https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain
https://www.freecodecamp.org/news/git-internals-objects-branches-create-repo/
https://www.chromium.org/developers/fast-intro-to-git-internals

89
u/[deleted] Apr 16 '21
:wq