使用“成功的 Git 分支模型”时,Github 中的“此分支提前 1 次提交,落后于主控者 1 次提交”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35672274/
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-19 11:50:05  来源:igfitidea点击:

"This branch is 1 commit ahead, 1 commit behind master" in Github while using "A successful Git branching model"

gitgithubgit-branchbranching-and-merging

提问by Victor

I am working in a clean repo with just a single file. I am the only developer.

我正在一个干净的仓库中工作,只有一个文件。我是唯一的开发者。

I want to do the develop-release-master workflow in A succesful git branching modelso I did:

我想在一个成功的 git 分支模型中执行开发-发布-主工作流,所以我做了:

Note: Please bear in mind that I have the fast forward off by default, so consider all the mergecommands as merge --no-ff.

注意:请记住,我默认关闭了快进,因此将所有merge命令视为merge --no-ff.

My origin is Github.

我的起源是 Github。

In masterbranch:

分支中:

git add .
git commit -m "Initial commit"
git push origin master
git checkout -b develop

In developbranch. I do a change to the file, then:

开发分支。我对文件进行了更改,然后:

git add .
git commit -m "work in the file"

I am ready to release this as the version 0.0

我准备将其发布为 0.0 版

git checkout -b release-0.0 develop

In release-0.0branch. I add a version number to the file.

release-0.0分支中。我在文件中添加了一个版本号。

git add .    
git commit -m "Bumped version 0.0"

I am ready to merge this release into master.

我已准备好将此版本合并到主版本中。

git checkout master
git merge release-0.0 -m "Releasing v0.0"
git tag -a 0.0 -m "Version 0.0"

... and into develop.

...并进入发展。

git checkout develop
git merge release-0.0 -m "Merge release 0.0 into develop"

Then I push both masterand developto Github

然后,我把两个发展到Github上

git push origin master
git push origin develop

When I check the developbranch in Github, it says:

当我检查Github 中的开发分支时,它说:

This branch is 1 commit ahead, 1 commit behind master.

该分支提前 1 次提交,落后于 master 1 次提交。

The masterbranch does not have a message like that.

分支机构不具有这样的消息。

What can I do to fix this? Both masterand developshould be equal at this point, as they were merged both with release-0.0.

我能做些什么来解决这个问题?此时masterdevelop应该相等,因为它们都与release-0.0合并。

采纳答案by TheGeorgeous

No it won't be equal, since you have fast forward disabled by default. Every merge creates a new commit and the merge commit has a different id. So the merge commit in master is not the merge commit in develop. And hence develop has a commit not in master while master has a commit not in develop. Hence the message in develop.

不,它不会相等,因为默认情况下您禁用了快进。每次合并都会创建一个新提交,并且合并提交具有不同的 id。所以master中的合并提交不是develop中的合并提交。因此,develop 有一个不在 master 中的提交,而 master 有一个不在 develop 中的提交。因此,开发中的消息。

As for the message not being there in master, that is because the message comes when a branch is compared to master. So if you compare master with master, the message is not necessary.

至于 master 中没有的消息,那是因为该消息是在将分支与 master 进行比较时出现的。因此,如果您将 master 与 master 进行比较,则不需要该消息。

One solution is to enable fast forward and explicitly create merge commits in release and master and then keep fast forwarding develop. The other option is to rebase develop after every merge to master. How you want to go about it is purely your personal choice depending on your workflow and code.

一种解决方案是启用快进并在 release 和 master 中显式创建合并提交,然后保持快进发展。另一种选择是在每次合并到 master 后 rebase develop。您想如何进行完全取决于您的工作流程和代码的个人选择。

Also the message being there isn't something you should be worried about as long as the code in the branches is exactly as you want.

此外,只要分支中的代码完全符合您的要求,您就不必担心存在的消息。

回答by Konipas

Just to add to the other answers:

只是添加到其他答案中:

The original git-flowhasn't been in development since 2012, and it has been superseded by git-flow AVH editionin many places (including the Ubuntu repositoriesand Git for Windows).

最初的git-flow自 2012 年以来一直没有开发,它在许多地方(包括Ubuntu 存储库Git for Windows)已被git-flow AVH 版本取代。

One of the differences introduced by the AVH edition is that the final merge is that of master* into developrather than that of releaseinto develop.

AVH 版本引入的差异之一是最终合并是master* 到develop 的合并,而不是releasedevelop 的合并。

This makes mastera direct parent of developand should eliminate one part of the message you see; only "1 commit ahead" should remain. It also makes it slightly easier to verify that master and develop have not diverged by accident.

这使得master成为develop的直接父级,并且应该消除您看到的消息的一部分;只应保留“提前 1 次提交”。它还可以更轻松地验证 master 和 develop 是否因意外而发生分歧。

* More precisely, it is the new tag (on master) that is merged into develop.

* 更准确地说,是合并到 develop 中的新标签(在 master 上)。

回答by 1ed

Because you are using --no-ffevery single merge will be a different commit. When you merge release-0.0into develop and into master the merge commits will be different. Here is how it looks like:

因为你使用的--no-ff每一个合并都会是一个不同的提交。当您合并release-0.0到 develop 和 master 时,合并提交将不同。这是它的样子:

commits

提交

As you can see the develop branch has one commit (Merge release 0.0 into develop) which is not in (not reachable from) the master and the master branch has one commit (Releasing v0.0) which is not in the develop branch. And that's what GitHub says with that message and it is totally fine (the contents are the same, but the commits different).

正如您所看到的,develop 分支有一个提交(将 0.0 版本合并到开发中),它不在 master 中(无法访问),而 master 分支有一个提交(Releasing v0.0),它不在 develop 分支中。这就是 GitHub 对该消息所说的,它完全没问题(内容相同,但提交不同)。

If you would like to use git flow you should take a look at https://github.com/nvie/gitflow, which will help you a lot.

如果你想使用 git flow,你应该看看https://github.com/nvie/gitflow,它会对你有很大帮助。