没有自动提交的 Git merge

标签 git

是否可以执行 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/

相关文章:

Git、SVN 和 Mercurial 最好的 SCM 是什么?

svn - 哪个 SCM 可以轻松处理 90,000 个文件

git - 如何检查特定的 pull 请求

git - 远程错误 : tls: access denied with go get

git - 如何在 IntelliJ IDEA 中审查 pull 请求?

ruby-on-rails - git push remote 在代理后面的问题

regex - 如何为 Github 设置此预提交消息 Hook ?

git - 监控 Jenkins 中的存储库,但不要 pull

git - 你如何让 bash 函数像其他东西一样自动完成?

git - 如何通过父项目中的 .gitattributes 强制子模块中的行结尾为 LF?