How to confirm changes after `git commit --amend` in Terminal?

28,292

Solution 1

Expanding on what William Pursell said, you probably ended up in vim. Save your changes and exit the editor by typing : to enter a command, followed by wq, then press enter. To exit vim without saving your changes do :q! instead.

To change this default to something you're more familiar with, you can set the EDITOR variable to something of your choice (try nano).

Just put export EDITOR=nano at the end of ~/.bash_profile (create the file if you don't already have it) to get this behaviour for every new terminal session.

Also, you could do git commit --amend -m 'Your message here' without a need for an editor at all.

Solution 2

Configure the editor like this (gedit as an example):

git config --global core.editor "gedit"

You can read the current configuration like this:

git config core.editor

You can also add the commit message from the command line.

git commit --amend -m "blablabla"

and the editor will not be opened at all.

Solution 3

It seems like this thread answers your question: Git - How to close commit editor?

Save the file in the editor. If it's Emacs: CTRLX CTRLS to save then CTRLX CTRLC > to quit or if it's vi: :wq

Press esc first to get out from editing. (in windows/vi)

Solution 4

If you use git bash command prompt, and you have not pushed yet. You can use

git commit --amend -m "new message"

If you have already pushed, you use rebase

git rebase -i HEAD~1

where 'i' means interface and '1' means the last one. If you want last two, you put '2'.

Rebase will take you into a very awkward 'VI' editor. Make sure your keyboard is in "INSERT" mode by insert key.

Then you overwrite the yellow word "pick" to "reword". Then you overwrite the old message after the funny id with your new command. Then you escape your INSERT mode by pressing "Esc" on your keyboard. Now you have to get out 'VI' and save.

Type :wq then hit "ENTER" to save your edit. If you see they give you more questions, hit another "ENTER"

Once you got back to the '$' mode, you do

git push --force

Good luck.

Solution 5

Just follow the instructions on the lower part of the screen. I remember it said that, press ^O to write out, and then if you have changed anything, it will let's you enter the file name to write to. Just press enter now.

NOTE THAT, ^O means Ctrl+O, and M-D means Esc+D on Ubuntu(as far as I know). This is what confuses us.

You can always use ^G to read the help info.

Share:
28,292

Related videos on Youtube

Bartłomiej Semańczyk
Author by

Bartłomiej Semańczyk

iOS developer and keen enthusiast of  and its development. Focused on clean code everytime while coding. I like Git very much:-) Swift is the only right language to programming on iOS. Implementing only latest solutions from Apple. Do not support old things. Tests are required, not optional:) #SOreadytohelp

Updated on October 02, 2020

Comments

  • Bartłomiej Semańczyk
    Bartłomiej Semańczyk over 3 years

    When I write git commit --amend I get some kind of editor, where I can change the name of this commit. How to confirm and save my changes using keyboard?

    • William Pursell
      William Pursell about 9 years
      Quit your editor! You're probably using a vi clone (probably vim). Try typing ":wq" and hit return. The colon takes you to command mode, then w to write the buffer, and then q to quit. Don't ever let someone tell you that ctrl-x ctrl-c is more intuitive than "wq" for "write-quit".
    • dot_Sp0T
      dot_Sp0T over 6 years
      @WilliamPursell even though I am late for the party, you should type up your comment as an answer. As of now your comment is the only thing on this question actually addressing the problem stated in the question.
    • Valary o
      Valary o over 3 years
      so you can write :wq you need to press ctrl+C to exit editor. If someone else face this problem
    • pkamb
      pkamb over 3 years
      Possible duplicate of Git - How to close commit editor?
    • rbento
      rbento about 3 years
      This question is not a duplicate as suggested. The answer is git commit --amend --no-edit which amends a commit without changing its commit message.
  • dot_Sp0T
    dot_Sp0T over 6 years
    While this answer brings up good alternatives it doesn't address the actual problem stated in the question.
  • dot_Sp0T
    dot_Sp0T over 6 years
    While this answer brings up good alternatives it doesn't address the actual problem stated in the question.