【问题标题】:Git merge doesn't use default merge message, opens editor with default messageGit合并不使用默认合并消息,打开带有默认消息的编辑器
【发布时间】:2012-09-26 23:11:17
【问题描述】:

如何强制git merge 使用默认的合并消息,而不是用所述消息加载我的编辑器?

git config -l 中没有列出编辑器,所以我不确定它为什么会打开编辑器。

【问题讨论】:

  • 不确定,但不合并 - 作为提交 - 有选项 --no-edit?

标签: git git-merge


【解决方案1】:

经过一番挖掘,找到了答案

编辑:根据马克的建议,这是最好的方法:

git config --global core.mergeoptions --no-edit

【讨论】:

  • 与其直接编辑~/.gitconfig,不如建议使用git config 来执行此操作更安全,例如git config --global core.mergeoptions --no-edit,这样就没有机会创建格式错误的~/.gitconfig。
  • 这似乎适用于git merge,但我仍然为git pull 开放了一个编辑器。有什么办法也可以禁用提交消息吗?
  • 我找不到任何提及core.mergeoptions,尽管它肯定适用于branch.*.mergeoptions。有谁知道这个支持的版本?
  • 这对我不起作用。合并和拉取仍然会在非 ff 合并上打开一个编辑器。使用 git 1.7.10.4
  • 浏览 git 源代码和发行说明表明现在没有,也从来没有core.mergeoptions。但是,当 git merge 本身被更改以调出编辑器时,将 GIT_MERGE_AUTOEDIT=no 添加到 git 1.7.10 中。正如@cmbuckley 所指出的,还有branch.*.mergeoptions 可用的选项。
【解决方案2】:

使用

export GIT_MERGE_AUTOEDIT=no

或

git merge --no-edit

【讨论】:

  • 这几乎是我想要的,但它迫使你每次都输入--no-edit。我找到的解决方案改变了git merge 的默认行为
  • 将它直接传递给合并命令,如此处所建议的,在调用 git merge 的脚本中特别有用。您几乎总是希望脚本不提示用户。但是,很高兴知道如何将自定义消息传递给git merge。也许git merge -m "message" 有效,但我还没有尝试过。
  • 对我来说,export GIT_MERGE_AUTOEDIT=no 在接受的答案 (git config --global core.mergeoptions --no-edit) 不起作用时起作用(用于合并)。
【解决方案3】:

这是 Git 的一项新功能,introduced in Git 1.7.10,使用旧功能(不要在合并时提供消息)将这两行放入您的 .bash_profile 或 .bashrc

GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT

【讨论】:

    【解决方案4】:

    试试这个

    git merge --no-ff --no-edit -m "my custom merge message" somebranch

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-26
      • 2012-01-24
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      • 2019-10-24
      • 1970-01-01
      相关资源
      最近更新 更多