git merge的时候总是会有一条commit message,请问这是操作不当吗?

分支情况:

  dev
  location
* master
  new

操作的时候使用命令:

git merge location

然后会出现commit message的注释

请问各位是什么地方出错了?

阅读 34.7k
2 个回答

没有错……
如果你使用git help merge,就会看到git merge的文档。
然后它提到:

Then "git merge topic" will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master,and record the result in a new commit along with the names of the two parent commits and a log message from the user describing the changes.

merge前

                  A---B---C topic
                /
           D---E---F---G master

merge后

                 A---B---C topic
                /         \
           D---E---F---G---H master

所以说,那个commit message是自动添加的。

如果你实在讨厌这个commit,可以在merge时添加--no-commit。这样就不会产生commit message了。不过我不推荐这么做,这样的话,就不容易区分merge的结果了。

除了使用--no-commit 在合并以前就取消提交以外,如果你已经合并了,但是不想提交,可以先
git commit
然后
git log找到上一个版本commit id(下文用xxxx指代)
git reset xxxx
然后再
git add .
git commit --amend就可以把合并进来的内容,放进之前的commit中了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题