git 如何避免“在提交消息中合并分支‘name_of_branch’?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3594894/
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
How to avoid "Merge branch 'name_of_branch' in commit messages?
提问by Sandra Schlichting
I remember that for about a year ago I did some merges that resulted in the commit messages being Merge branch 'Name_of_branch'
on the remote repository.
我记得大约一年前,我进行了一些合并,导致提交消息Merge branch 'Name_of_branch'
位于远程存储库中。
From what I remember it would happen if I rebased all commits in a branch and then merged it to master and then pushed to remote repository.
根据我的记忆,如果我重新调整分支中的所有提交,然后将其合并到 master 然后推送到远程存储库,就会发生这种情况。
But now I can't reproduce it with git-1.7.2.2.
但现在我无法用 git-1.7.2.2 重现它。
Have it been fixed? Or can someone explain how this happens, and perhaps how to avoid it?
修好了吗?或者有人可以解释这是如何发生的,也许如何避免它?
回答by Cascabel
That's a default merge commit message. It doesn't take anything special to get it - just do any nontrivial merge into master:
这是默认的合并提交消息。获得它并不需要任何特别的东西 - 只需对 master 进行任何非平凡的合并:
- o - o - X (master)
\ /
o - o (topic)
The default commit message for commit X will be "Merge branch 'topic'". If you merge into a branch other than master, the default message is "Merge branch '<merged-branch>' into '<branch>'"
.
提交 X 的默认提交消息将是“合并分支‘主题’”。如果合并到 master 以外的分支,则默认消息为"Merge branch '<merged-branch>' into '<branch>'"
.
I'm not sure why you're asking about "fixing" and "avoiding" this. It's a very reasonable default message for a merge commit. If you'd like a more detailed merge commit message, you're certainly welcome to provide one. (The two primary ways are to use git merge --no-commit
followed by git commit
, or git merge
followed by git commit --amend
to edit the message.)
我不确定你为什么要问“修复”和“避免”这个问题。这是合并提交的非常合理的默认消息。如果您想要更详细的合并提交消息,当然欢迎您提供。(两种主要方法是使用git merge --no-commit
后跟git commit
或git merge
后跟git commit --amend
来编辑消息。)
Perhaps you're used to doing only fast-forward merges? (Those are trivial merges, where the commit you're merging has your current branch as ancestor, so all git has to do is move the branch forward through history.) Those don't generate merge commits, so there's no commit message.
也许您习惯于只进行快进合并?(那些是琐碎的合并,您正在合并的提交将您当前的分支作为祖先,因此 git 所要做的就是在历史中向前移动分支。)这些不会生成合并提交,因此没有提交消息。
(By the way, pushing has nothing to do with this - all it does is copy information from one repo to another. It doesn't ever create commits.)
(顺便说一句,推送与此无关 - 它所做的只是将信息从一个 repo 复制到另一个 repo。它永远不会创建提交。)
回答by user3770488
git merge -m
git merge -m
I am using git 1.7.8
我正在使用 git 1.7.8
回答by bradoaks
I don't mind the automatic message, but I did want to avoid having to exit my editor just to keep the default. The following option achieves that behavior (in a script of mine):
我不介意自动消息,但我确实想避免为了保留默认值而不得不退出我的编辑器。以下选项实现了该行为(在我的脚本中):
GIT_MERGE_AUTOEDIT=no git merge origin/master