当 VI 在屏幕上等待提交消息时,如何停止 Git 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4323440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:35:17  来源:igfitidea点击:

How do I stop a Git commit when VI is on the screen waiting for a commit message?

git

提问by Ben Aston

I have asked Git to perform a commit from within git bash, It has brought up VI as it always does.

我已经要求 Git 从 git bash 中执行提交,它像往常一样带来了 VI。

I now wish to cancel the commit, how do I prevent proceeding with the commit from this point?

我现在希望取消提交,如何阻止从这一点开始提交?

回答by Eugene Yarmash

You have two options:

您有两个选择:

  • Provide an empty commit message. If it's a new commit and you haven't yet saved the message, you can simply use :q!(quit without saving). If you've already saved (or you're amending a previous commit), just delete the entire log message and save again. This can be done with ggdG+ :wqin Vim.

  • Have the editor exit with a non-zero exit code. In Vim, you can use :cq(quit with an error code).

  • 提供一个空的提交消息。如果这是一个新的提交并且您还没有保存消息,您可以简单地使用:q!(quit without save )。如果您已经保存(或者您正在修改之前的提交),只需删除整个日志消息并再次保存。这可以在 Vim 中使用ggdG+来完成:wq

  • 让编辑器以非零退出代码退出。在 Vim 中,您可以使用:cq(quit with an error code)。

It's worth noting that you can always reset your working copy to the state it was in before the commit with git reset HEAD^.

值得注意的是,您始终可以将工作副本重置为使用git reset HEAD^.

回答by Daniel Pinyol

  • :q!does not work when amending a commit. It does not update the commit message, but it executes the amendment :-(
  • :cqcompletely aborts the amendment.
  • :q!修改提交时不起作用。它不会更新提交消息,但会执行修改:-(
  • :cq完全中止修改。

回答by Maciej Piekarski

To sum up:

总结:

  • When creating a new commit(i.e git commit) quit using :q!.
  • When amending(i.e. git commit --amend) remove the commit message (only the first few rows notbeginning with a #) for example by holding v and using arrow keys to select it and then pressing Delete. Quit with :wqto apply changes! If you use :q!the changes will be lost and the previous commit message will be used.
  • 创建新提交时(即git commit)使用:q!.
  • 修改(即git commit --amend)删除提交消息(仅前几行以# 开头)时,例如按住 v 并使用箭头键选择它,然后按 Delete。退出:wq以应用更改!如果使用:q!,更改将丢失,并且将使用先前的提交消息。

When using VIM it's ok in both cases to quit with :cq- VIM will quit with an error code and the commit will be aborted.

使用 VIM 时,在两种情况下都可以退出:cq- VIM 将退出并显示错误代码并且提交将被中止。