git 推送分支和合并到主然后推送有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18222728/
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
What is the difference between push branch and merge to master then push?
提问by Magicloud
One way:
单程:
git checkout myBranch
git push origin myBranch:master
Another way:
其它的办法:
git checkout master
git merge myBranch
git push
What is difference between these two?
这两者有什么区别?
采纳答案by Magicloud
This:
这个:
git checkout myBranch
git push origin myBranch:master
just attempts to do a fast-forward (i.e. non-forced update) push of myBranch
to master
. If master
is reachable from myBranch
, i.e. master
doesn't contain any commits that myBranch
doesn't also have, then the push will succeed; otherwise, the push will be rejected.
只是尝试做一个快进的(即非强制更新)推myBranch
到master
。如果master
可以从myBranch
,即master
不包含任何也没有的提交myBranch
,则推送将成功;否则,推送将被拒绝。
The preceding git checkout myBranch
is irrelevant to the git push
, since you're using the refspec myBranch:master
. You can learn more about refspecs at Git Internals - The Refspec.
前面git checkout myBranch
的与 无关git push
,因为您使用的是 refspec myBranch:master
。您可以在Git Internals - The Refspec 中了解有关refspecs 的更多信息。
This:
这个:
git checkout master
git merge myBranch
git push
actually merges myBranch
into master
, and then attempts to push it to a remote (with a default configuration of a Git repo, the remote will be origin).
实际上合并myBranch
到master
,然后尝试将其推送到远程(使用 Git 存储库的默认配置,远程将是原点)。
Because myBranch
is actually merged into master
, then assuming the remote master
is behind the local one, i.e. it doesn't contain commits that the local one doesn't also have, then the push will succeed, otherwise it will fail.
因为myBranch
实际上是合并到master
,那么假设远程master
在本地之后,即它不包含本地也没有的提交,那么推送将成功,否则将失败。