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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:46:13  来源:igfitidea点击:

What is the difference between push branch and merge to master then push?

git

提问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 myBranchto master. If masteris reachable from myBranch, i.e. masterdoesn't contain any commits that myBranchdoesn't also have, then the push will succeed; otherwise, the push will be rejected.

只是尝试做一个快进的(即非强制更新)推myBranchmaster。如果master可以从myBranch,即master不包含任何也没有的提交myBranch,则推送将成功;否则,推送将被拒绝。

The preceding git checkout myBranchis 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 myBranchinto master, and then attempts to push it to a remote (with a default configuration of a Git repo, the remote will be origin).

实际上合并myBranchmaster,然后尝试将其推送到远程(使用 Git 存储库的默认配置,远程将是原点)。

Because myBranchis actually merged into master, then assuming the remote masteris 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在本地之后,即它不包含本地也没有的提交,那么推送将成功,否则将失败。