从打开文本编辑器中停止 git merge

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24609146/
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-19 10:11:21  来源:igfitidea点击:

stop git merge from opening text editor

gitmerge

提问by Holly

Every time i run a git merge command it opens the text editor asking me to add an extra message.

每次我运行 git merge 命令时,它都会打开文本编辑器,要求我添加额外的消息。

How can I stop git from opening the editor & simply merging my branches? Because when it opens the editor it doesn't complete the merge, even if I add an extra message & save the file, the terminal just hangs on my git merge command.

如何阻止 git 打开编辑器并简单地合并我的分支?因为当它打开编辑器时它不会完成合并,即使我添加了额外的消息并保存文件,终端也会挂在我的 git merge 命令上。

Merge branch 'my-feature-branch' into main-development

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
# 
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

Update

更新

Zeeker's answer was correct but I was also having an issue with sublime text 2 in linux. Even though I saved & closed the editor the terminal hung, I believe it was because my last project folder in the editor was opening when with the git merge file. I removed the project from sublime, opened another sublime window, closed the original sublime window & then closed the new sublime window. After this, once I ran the giy merge command & new sublime window without the project opened & once I closed the git merge command executed.

Zeeker 的回答是正确的,但我在 linux 中也遇到了 sublime text 2 的问题。即使我保存并关闭了终端挂起的编辑器,我相信这是因为我在编辑器中的最后一个项目文件夹在使用 git merge 文件时正在打开。我从 sublime 中删除了项目,打开了另一个 sublime 窗口,关闭了原来的 sublime 窗口,然后关闭了新的 sublime 窗口。在此之后,一旦我在没有打开项目的情况下运行了 giy merge 命令和新的 sublime 窗口,并且一旦我关闭了执行的 git merge 命令。

回答by Sascha Wolf

Use the --no-editoption, you can read about it in the documentation.

使用该--no-edit选项,您可以在文档中阅读它。

Note that using the default message is discuraged, since it provides no meaningful information about the changes introduced with this merge.

请注意,不建议使用默认消息,因为它没有提供有关此合并引入的更改的有意义的信息。



On a sidenote: To continue merging you probably have to close the editor.

旁注:要继续合并,您可能必须关闭编辑器。



If you have a git version prior to 1.7.8there is still a way to achieve what you want by using the envcommand.

如果您之前有一个 git 版本,1.7.8仍然可以通过使用该env命令来实现您想要的。

env GIT_EDITOR=: git merge <ref-you-want-to-merge>

For easier usage you could create an alias.

为了更容易使用,您可以创建一个别名。

git config --global alias.merge-no-edit '!env GIT_EDITOR=: git merge'

Which then can be used using git merge-no-edit <ref-you-want-to-merge>.

然后可以使用git merge-no-edit <ref-you-want-to-merge>.

回答by Fredszaq

You can use

您可以使用

git merge --no-edit

This is the man page :

这是手册页:

--edit, -e, --no-edit Invoke an editor before committing successful mechanical merge to further edit the auto-generated merge message, so that the user can explain and justify the merge. The --no-edit option can be used to accept the auto-generated message (this is generally discouraged). The --edit (or -e) option is still useful if you are giving a draft message with the -m option from the command line and want to edit it in the editor.

Older scripts may depend on the historical behaviour of not allowing the user to edit the merge log message. They will see an editor opened when they run git merge. To make it easier to adjust such scripts to the updated behaviour, the environment variable GIT_MERGE_AUTOEDIT can be set to no at the beginning of them.

--edit, -e, --no-edit 在提交成功的机械合并之前调用编辑器以进一步编辑自动生成的合并消息,以便用户可以解释和证明合并。--no-edit 选项可用于接受自动生成的消息(通常不鼓励这样做)。如果您从命令行提供带有 -m 选项的草稿消息并希望在编辑器中对其进行编辑,则 --edit(或 -e)选项仍然很有用。

较旧的脚本可能取决于不允许用户编辑合并日志消息的历史行为。当他们运行 git merge 时,他们会看到一个打开的编辑器。为了更容易地将此​​类脚本调整为更新的行为,环境变量 GIT_MERGE_AUTOEDIT 可以在它们的开头设置为 no。