为什么在git合并后我不需要提交?

16

我有一个代码库的主分支,我对file1.txt和file2.txt进行操作。

git checkout -b fix1

我接着修改了file1.txt文件

然后我执行了一个操作

git commit -a

然后我做a。

git checkout master

然后我执行一个

git checkout -b fix2

我接着改变file2.txt文件

然后我执行一个

git commit -a

然后运行git checkout master命令,之后执行a操作。

git merge fix1
git marge fix2 
但是如果我这样做。
 commit -a 

我明白了

# 在主分支上
没有要提交的内容(工作目录干净)
3个回答

24

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.

3
如果合并成功且没有冲突,git将自动提交它(您可以通过简单检查git log来验证)。文档注释(重点添加):“git merge topic”将在主分支(即E)与当前提交(C)分叉后,重新应用在主分支上的主题分支所做的更改,并将结果记录在一个新的提交中,其中包括两个父提交的名称和用户描述更改的日志消息。如果要避免这种情况,请使用--no-commit标志:
git merge --no-commit fix1

1
合并后没有冲突的文件已经合并完成,您可以直接推送已合并的文件。

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