合并后Git提交会打开VIM

21

我合并了两个文件,现在尝试进行提交,但它打开了VIM并显示以下数据,我完全不知所措。(我没有使用VIM的经验)

Merge branch 'master' of nodester.com:/node/git/lolcoder/****-******

Conflicts:
        .gitignore
        server.js
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
#       .git/MERGE_HEAD
# and try again.


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#   
#       .project
~                                                                               
~                                                                               
~                                                                               
".git/COMMIT_EDITMSG" 19L, 521C                               1,1           All

接下来该怎么做?

以下是场景:

我在GitHub上有一个node.js项目,现在我想将其推送到nodester的git仓库(所以我的项目现在有两个远程仓库)。但在推送到nodester之前,我需要修复与nodester为我生成的文件冲突的2个文件。我用git merge -y解决了这些冲突,现在我想要提交并推送。

这是当我尝试推送到nodester时收到的错误信息:

Nodester!
To git@nodester.com:/node/git/lolcoder/****-**************.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@nodester.com:/node/git/lolcoder/****-************.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

这与node.js或nodster无关,请仅使用适当的标签。在这种情况下是GIT。 - thenetimp
我认为这是git的一个“糟糕”特性。它只会使它变得不那么自动化。我必须包装git命令以使其再次自动化。--message "save" 对我有用。 - bronze man
3个回答

17

Git打开vim是因为你的环境变量EDITOR被设为vim,而Git认为你需要为合并操作提供提交信息,因此它会为你打开一个编辑器,让你输入信息。

你可以通过将环境变量EDITOR更改为任何你喜欢的值,或者在git merge -y之后添加--message "this is my commit message"参数来解决这个问题。


我执行了 git commit -- "message" - Shawn Mclean
1
编辑器变量的默认值是什么?这在我之前从未发生过,我想返回默认行为。 - Leonel Galán
默认值因系统而异。我不知道你之前的默认值是什么。如果你没有永久更改 EDITOR 变量(在你的 .bashrc 或类似文件中),那么你可能只需要打开一个新终端,就可以回到正常状态了。 - mattbornski

7

如果您想执行合并并避免打开任何文本编辑器,您可以在合并命令中添加--no-edit选项,这样它就不会为提交消息打开编辑器。


4
如果您希望完全跳过文本编辑器并使用默认的合并消息,只需将以下行添加到您的.bash_profile.bashrc.zshrc文件中:
export GIT_MERGE_AUTOEDIT=no

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接