用于将远程“origin/develop”合并到“origin/master”的 Git 工作流程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15601016/
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 workflow for merging remote ‘origin/develop’ into ‘origin/master’
提问by Todd
With unlimited lifetimes for ‘develop' and ‘master', what's the best workflow for merging and tagging a GitHub remote ‘origin/develop' branch into the remote ‘origin/master' without the remote ‘master' getting ahead of remote ‘develop'?
有了“开发”和“主”的无限生命周期,将 GitHub 远程“源/开发”分支合并和标记到远程“源/主”而不让远程“主”领先于远程“开发”的最佳工作流程是什么? ?
Scenario for updating a file (readme) and tagging the ‘master'...
更新文件(自述文件)和标记“主”的场景...
Everything agrees...
一切都同意...
$ git log develop ^master
$ git log master ^develop
$ git log master ^origin/master
$ git log master ^origin/develop
$ git log develop ^origin/develop
$ git log develop ^origin/master
Switch to ‘develop'...
切换到“开发”...
**$ git branch**
* develop
master
Edit README.md file.
编辑 README.md 文件。
Commit to local repo...
致力于本地回购...
**$ git commit -a**
[develop 47c8393] Updated branching model
1 file changed, 18 insertions(+), 6 deletions(-)
rewrite README.md (81%)
Push ‘develop' to remote ‘develop'...
将“开发”推送到远程“开发”...
**$ git push origin develop**
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 745 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To [email protected]:xxx/xxx.git
038cb2b..47c8393 develop -> develop
Switch to ‘master'...
切换到“主人”...
**$ git checkout master**
Switched to branch 'master'
Merge ‘develop' into ‘master'...
将“发展”合并为“大师”...
**$ git merge --no-ff develop**
Merge made by the 'recursive' strategy.
README.md | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
Tag ‘master'...
标记“大师”...
**$ git tag -a v3.0.2**
Push ‘master' to remote ‘master'...
将“master”推送到远程“master”...
**$ git push --tags origin master**
Counting objects: 2, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 442 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
To [email protected]:xxx/xxx.git
038cb2b..5750fa7 master -> master
* [new tag] v3.0.2 -> v3.0.2
GitHub now reports remote ‘master' is 1 ahead of remote ‘develop' (the merge). Shouldn't they agree?...
GitHub 现在报告远程“master”比远程“develop”(合并)领先 1。他们不应该同意吗?...
**$ git log origin/master ^origin/develop**
commit 5750fa78ff81f41ef2327c2f4595f98c0413e245
Merge: 038cb2b 47c8393
Author:
Date:
Merge branch 'develop'
If the ‘master' is merged back into ‘develop', the HEAD points to ‘develop', is this a problem? Should a new ‘develop' be branched from the new ‘master' (not supporting unlimited lifetime for ‘develop')?
如果'master'合并回'develop',HEAD指向'develop',这是一个问题吗?是否应该从新的“master”分支出一个新的“develop”(不支持“develop”的无限生命周期)?
采纳答案by David Culp
In git, merging/rebasing occurs locally, so if you want the two remotes to agree you have to make them agree locally first.
在 git 中,合并/变基在本地发生,因此如果您希望两个遥控器达成一致,则必须先让它们在本地达成一致。
Making the command git merge --no-ff develop
on master creates a new commit on master
that contains all of the commits on develop
. This new commit on master
is not the same as any of the commits on develop
, even when there is only one commit on develop
.
git merge --no-ff develop
在 master 上执行命令会创建一个新的提交,master
其中包含 上的所有提交develop
。这个新提交master
与任何提交都不同develop
,即使只有一个提交develop
。
Using --no-ff
always creates a new commit, so it will always ensure the branches are different -- the same is true if you combine commits, regardless of how.
使用--no-ff
always 会创建一个新的提交,所以它总是会确保分支是不同的——如果你组合提交也是如此,不管如何。
If you want to keep the branches the same look into a workflow that uses git rebase
instead of git merge
, such as (A Rebase Workflow for Git).
如果您想在使用git rebase
而不是 的工作流中保持分支相同的外观git merge
,例如(A Rebase Workflow for Git)。
回答by vonbrand
You should merge localbraches, and push out the result. I.e., merge develop into master. If you don't want to mess up local branches, create branches just for this, do the merging an pushing back, and remove them. Or even create a clone just for this.
您应该合并本地分支,并推出结果。即,合并发展成为大师。如果您不想弄乱本地分支,请为此创建分支,进行合并和推回,然后删除它们。或者甚至为此创建一个克隆。