没有自动提交的 Git 合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8640887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git merge without auto commit
提问by selbie
Is it possible to do a git merge
, but without a commit?
是否可以执行 a 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. Here's what I did:
但是,当我尝试使用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)
A subsequent git log
reveals all the commits from the v1.0 branch merged into master.
随后git log
显示了来自合并到 master 的 v1.0 分支的所有提交。
回答by manojlds
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
回答by Samus_
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; 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.
在--no-commit
防止合并提交发生,当你合并两个不同分支历史只会发生; 在您的示例中,情况并非如此,因为 Git 表示这是一个“快进”合并,然后 Git 仅按顺序应用分支上已经存在的提交。
回答by Adrian Li
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
回答by Pellet
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:
然后它会说你的分支领先于“ #
”提交,你现在可以弹出这些提交并将它们放入工作更改中,如下所示:
git reset @~#
For example if after the merge it is 1 commit ahead, use:
例如,如果合并后提前 1 次提交,请使用:
git reset @~1
Note: On Windows, quotes are needed. (As Joshnoted in comments) eg:
注意:在 Windows 上,需要引号。(正如乔希在评论中指出的)例如:
git reset "@~1"
回答by Sithu
When there is one commit only in the branch, I usually do
当分支只有一个提交时,我通常会这样做
git merge branch_name --ff