是否可以执行 git merge
,但没有提交?
“man git merge”是这样说的:
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.
但是当我尝试将 git merge
与 --no-commit
一起使用时,它仍然会自动提交。这是我所做的:
$> ~/git/testrepo$ git checkout master
Switched to branch 'master'
$> ~/git/testrepo$ git branch
* master
v1.0
$> ~/git/testrepo$ git merge --no-commit v1.0
Updating c0c9fd2..18fa02c
Fast-forward
file1 | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
$> ~/git/testrepo$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
随后的 git log
显示 v1.0 分支中的所有提交都已 merge 到 master 中。
最佳答案
注意 merge 时的输出 - 它说 Fast Forward
在这种情况下,你想做的是:
git merge <name-of-branch> --no-commit --no-ff
重要:如果您这样做,那么您将无法对暂存区中的文件进行任何更改,例如您不能删除/添加文件或对文件进行任何更改。
如果你想 merge 更改然后提交,就好像你手动输入了你 merge 的所有更改(而不是传统的 merge )你需要运行 rm .git/MERGE_HEAD
之后,这将迫使 git 忘记 merge 的发生。
关于没有自动提交的 Git merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8640887/