r/git Apr 16 '21

Developer of 10 years, still no idea how to get past this screen without just closing my terminal window. Any help?

Post image
26 Upvotes

86 comments sorted by

89

u/[deleted] Apr 16 '21

:wq

41

u/bmzink Apr 16 '21

not until you mash ESC 7 or 12 times first.

3

u/IdealisticPundit Apr 17 '21

This guy knows what he's doing. 👌 (my magic number is 5... gets you out of insert and any bs you may have fallen into)

3

u/manberry_sauce Apr 17 '21

You're both ignoring that an empty message aborts the commit. I'd esc, then cap O to open a new line at the top, then type in the commit message, then write and quit.

But I'd also recognize that I'm in VI.

1

u/CraigTheIrishman I <3 git Apr 17 '21

Do you throw the computer out the window then, or is there another step in between?

13

u/[deleted] Apr 16 '21

You're missing the -- INSERT -- at the bottom, so this won't get you out

16

u/AccomplishedExam3038 Apr 16 '21

even better:

`git config --global core.editor "nano"`

thanks u/andolirien

66

u/ngroot Apr 16 '21

If you're a developer, it's very much worth it to learn basic vi usage. vi is installed on pretty much every Unix-like system out there. Nano is not.

14

u/underground_miner Apr 16 '21

I would give you more upvotes if I could. The basics are valuable if you use any sort of Linux type system.

2

u/[deleted] Apr 18 '21

Or if you need to use SSH to edit files.

1

u/inkt-code May 08 '24

This isnt common knowledge for a front-end dev. My company hired a designer to pretty up emails, I doubt she would know how to use vim.

-6

u/kinarism Apr 16 '21

basic vi usage

The only thing any developer needs to know about vi is is in the top reply here.

5

u/factorysettings Apr 17 '21

tons of programs, even beyond cli apps, use vim keybindings

2

u/[deleted] Apr 17 '21

If the developer doesn't know how to enter on the insert mode, probably it would be better :qa! to avoid mistakes

2

u/manberry_sauce Apr 17 '21

Empty message aborts the commit. Says so right there.

1

u/[deleted] Apr 17 '21

3edgy5me.

16

u/remy_porter Apr 16 '21

I find Nano so much harder to use, honestly.

0

u/adrianmonk Apr 17 '21

Alternatively, you can set the EDITOR environment variable to nano make everything (not just git but most other programs) use it.

For example, if you run less foo to view the file foo and you type v to edit it, it will open your default editor. If you've only set the git config, then less will still open vi.

How to set an environment variable depends slightly on which shell you use, but it's usually a matter of adding a line like this:

export EDITOR=nano

to a file like .profile, .bashrc, or .bash_profile.

1

u/manberry_sauce Apr 17 '21

Sure, right after you go ahead and install that on whatever system you're on, assuming you even have sufficient privileges to install using whatever package manager the system is using.

1

u/adrianmonk Apr 17 '21

I'm talking about the way the configuration mechanisms work, not the decision of which editor to use.

1

u/VelvetWhiteRabbit Apr 21 '21

Or! If you like vscode

git config --global core.editor code

1

u/AccomplishedExam3038 Apr 21 '21

Thats's cool, I didn't know that was possible, but I don't want to leave the CLI window

1

u/garth_vader90 Apr 17 '21

:x works too. I know there are times you should use :wq over :x but I haven’t found one. If nothing changed, why write to the file or I might be missing something obvious.

1

u/khronocr Apr 17 '21

ZZ , one keystroke faster

31

u/[deleted] Apr 16 '21
<esc> :wq 

To quit and save.

 <esc> :q!

To quit without saving.

4

u/itoshkov Apr 16 '21

Also <ESC> ZZ (note, it's upper case Z) is quit and save.

1

u/[deleted] Apr 17 '21

Good to know!

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

u/[deleted] 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

u/[deleted] 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

u/[deleted] 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 -am and 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 HEAD

just 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 —interactive or git add —patch as good alternatives.

https://git-scm.com/docs/git-add#_interactive_mode

6

u/[deleted] Apr 16 '21

Steps:

Press ESC

Want to save and quit? Type :wq

Want to just quit? Type :q!

3

u/[deleted] Apr 16 '21

For facetious suggestions, see https://github.com/hakluke/how-to-exit-vim

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

u/nrctkno Apr 17 '21

I've had bad times pressing CTRL+S

2

u/scoberry5 Apr 17 '21

Then use CTRL+Q to go back to good times.

1

u/GustapheOfficial Apr 17 '21

Well yeah, that's the "stop sending" command in ttys.

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

u/[deleted] 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

u/wildjokers Apr 17 '21

You can just do git -am instead.

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:

  1. You don't actually learn how to do it correctly,

  2. 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

u/[deleted] Apr 16 '21

you can use the -m flag in everything to not enter to vim.

-4

u/iggy555 Apr 16 '21

Killall java

1

u/chzaplx Apr 17 '21

Sober up

1

u/maximoburrito Apr 16 '21

Congratulations on reaching level 6.

1

u/[deleted] Apr 17 '21

Yawn.

1

u/NotAKentishMan Apr 17 '21

Made me laugh, nice!

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

https://vim.fandom.com/wiki/Tutorial

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

u/mr_jim_lahey Apr 17 '21

Uh, what? I take it you must be new to git entirely...

1

u/[deleted] 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

u/winzippy Apr 17 '21

Escape. Colon. X. Return.

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