当前位置:   article > 正文

没有自动提交的Git合并_git merge 不commit

git merge 不commit

本文翻译自:Git merge without auto commit

Is it possible to do a git merge , but without a commit? 是否有可能进行git merge ,但没有提交?

"man git merge" says this: “man git merge”说:

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

But when I try to use git merge with the --no-commit it still auto-commits. 但是当我尝试将git merge--no-commit它仍然会自动提交。 Here's what I did: 这是我做的:

  1. $> ~/git/testrepo$ git checkout master
  2. Switched to branch 'master'
  3. $> ~/git/testrepo$ git branch
  4. * master
  5. v1.0
  6. $> ~/git/testrepo$ git merge --no-commit v1.0
  7. Updating c0c9fd2..18fa02c
  8. Fast-forward
  9. file1 | 1 +
  10. 1 files changed, 1 insertions(+), 0 deletions(-)
  11. $> ~/git/testrepo$ git status
  12. # On branch master
  13. # Your branch is ahead of 'origin/master' by 1 commit.
  14. #
  15. nothing to commit (working directory clean)

A subsequent git log reveals all the commits from the v1.0 branch merged into master. 随后的git log显示v1.0分支中的所有提交都合并到master中。


#1楼

参考:https://stackoom.com/question/aFt9/没有自动提交的Git合并


#2楼

If you only want to commit all the changes in one commit as if you typed yourself, --squash will do too 如果您只想在一次提交中提交所有更改,就像您自己键入一样,--squash也会这样做

  1. $ git merge --squash v1.0
  2. $ git commit

#3楼

I prefer this way so I don't need to remember any rare parameters. 我更喜欢这种方式,因此我不需要记住任何罕见的参数。

git merge branch_name

It will then say your branch is ahead by # commits, you can now pop these commits off and put them into the working changes with the following: 然后它会通过#commit声明你的分支领先,你现在可以弹出这些提交并将它们放入工作更改中,具体如下:

git reset @~#

For example if after the merge it is 1 commit ahead, use: 例如,如果在合并之后提前1次提交,请使用:

git reset @~1

#4楼

当只在分支中有一个提交时,我通常会这样做

git merge branch_name --ff

#5楼

You're misunderstanding the meaning of the merge here. 你在这里误解了合并的含义。

The --no-commit prevents the MERGE COMMIT to occur, and that only happens when you merge two divergent branch histories; --no-commit阻止MERGE COMMIT发生,并且仅在合并两个不同的分支历史时发生; in your example that's not the case since Git indicates that it was a "fast-forward" merge and then Git only applies the commits already present on the branch sequentially. 在你的例子中并非如此,因为Git表明它是一个“快进”合并,然后Git只按顺序应用已经存在于分支上的提交。


#6楼

Note the output while doing the merge - it is saying Fast Forward 在进行合并时请注意输出 - 它表示Fast Forward

In such situations, you want to do: 在这种情况下,你想做:

git merge v1.0 --no-commit --no-ff
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/321389
推荐阅读
相关标签
  

闽ICP备14008679号