本文翻译自: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”说:
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.
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: 这是我做的:
$> ~/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)
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也会这样做
$ git merge --squash v1.0
$ 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