为什么我不必在git merge之后提交

时间:2013-02-12 15:31:48

标签: git git-merge

我有一个repo master,我使用file1.txt和file2.txt

git checkout -b fix1

然后我改变了file1.txt

我做了

git commit -a

然后我做了

git checkout master

然后我做了

git checkout -b fix2

然后我改变了file2.txt

我做了

git commit -a

然后git checkout master

git merge fix1
git marge fix2 

但如果我做了

 commit -a 

我得到了

# On branch master
nothing to commit (working directory clean)

3 个答案:

答案 0 :(得分:10)

git merge自动提交。如果您不想提交,请添加--no-commit参数:

  --commit, --no-commit
      Perform the merge and commit the result. This option can be used to override --no-commit.

      With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user
      a chance to inspect and further tweak the merge result before committing.

答案 1 :(得分:3)

如果合并成功而没有冲突,git将自动提交它(您应该只需检查git log即可验证)。

The documentation notes(强调补充):

  

...“git merge topic”将重播在主题分支上所做的更改,因为它从master(即E)分支到master当前提交(C),并将结果记录在新提交以及两个父提交的名称和来自用户的描述更改的日志消息

如果您想避免这种情况,请使用--no-commit标志:

git merge --no-commit fix1

答案 2 :(得分:1)

已合并没有冲突的合并文件。您可以直接推送合并的文件。