How to cancel a local git commit

前端 未结 6 2018
抹茶落季
抹茶落季 2021-01-29 17:20

My issue is I have changed a file eg: README, added a new line \'this for my testing line\' and saved the file, then I issued the following commands

 gi         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 17:28

    If you're in the middle of a commit (i.e. in your editor already), you can cancel it by deleting all lines above the first #. That will abort the commit.

    So you can delete all lines so that the commit message is empty, then save the file:

    You'll then get a message that says Aborting commit due to empty commit message..

    EDIT:

    You can also delete all the lines and the result will be exactly the same.

    To delete all lines in vim (if that is your default editor), once you're in the editor, type gg to go to the first line, then dG to delete all lines. Finally, write and quit the file with wq and your commit will be aborted.

提交回复
热议问题