当我将发布分支合并到 main 中,然后合并到 dev 中以合并其中的更改时,我的开发人员说 X 提交在前面,X 提交在后面。为什么?

发布于 2025-01-13 04:47:01 字数 524 浏览 1 评论 0原文

我正在遵循 gitflow 分支 模型。我非常严格地遵循这些准则。

  • 我从 dev 创建一个发布分支,并在那里进行最终的错误修复和调整,
  • 然后将其合并到 main 中,然后合并到 dev 中,然后删除发布分支
  • 我在合并时使用 --no-ff (无快进)标志我的发布分支分为 main 和 dev,
  • 目前我唯一不遵循的就是在将发布的更改合并到其中后,从 git 标记我的 main。相反,我使用发布功能从 GitHub 存储库中标记它。

然而,我的开发分支现在这样说:

此分支提前 1 次提交,主分支后 1 次提交。

我对此感到困惑。看来每个分支上的新合并提交(由将发行版合并到 dev 和 main 中引起)是唯一的区别。这应该发生吗?我做错了什么吗?

I'm following the gitflow branching model. I follow the guidelines quite closely.

  • I create a release branch from dev, and make final bugfixes and adjustments there
  • I then merge this into main, and then into dev, and then delete the release branch
  • I use the --no-ff (no fast-forward) flag when merging my release branch into both main and dev
  • the only thing that I currently don't follow is tagging my main from git after incorporating the changes from release into it. Instead I tag it from the GitHub repo using the releases feature.

However, my dev branch now says this:

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

I'm confused by this. It appears that the new merge commit (caused by merging release into dev and main) on each branch is the only difference. Is this supposed to happen? Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2025-01-20 04:47:01

这完全没问题,并且在某些情况下是预期的。让我们来看看发生了什么:

  1. 您从 develop 的提示创建了分支 release。此时 developrelease 是相同的。
  2. 您将一些包含错误修复的提交添加到 release (或者不添加,它实际上不会改变这个问题的结果)。
  3. 一旦您对 release 感到满意,您就可以使用 --no-ff (无快进)将其部署并合并到 main 中旗帜。这会在 main 上创建一个新的合并提交。因此,此时 releasemain 具有相同的内容,但 main 上有一个额外的提交。
  4. 现在,您还可以将 release 合并回 develop,同样使用 --no-ff。这会在 develop 上创建一个新的提交,该提交不在 releasemain 上。
  5. 现在您删除release

因此,此时,develop至少 1 个不在 main 上的提交,并且 main 恰好有一项提交不在 develop 中。据推测,自创建 release 分支以来,您没有向 develop 添加任何提交,因此 develop 将比 早 1 次提交main,并且在 main 之后恰好有 1 次提交。

注意:下次执行 release 分支时,将会发生相同的过程,但最终您将在 main 上得到 2 次提交t 在 develop 中,并且这将继续递增,直到您执行第一个 hotfix 分支,这会将所有旧的合并提交带回 develop一键完成。这是预料之中的,但第一次看到它时可能会感到困惑。

提示:在经历了 hotfix 分支将许多合并提交带回 develop 后,现在当我在使用 Git Flow 的存储库中工作时,合并后 < code>release 到 main 中,我更喜欢将 main 合并到 develop 中,而不是将 release 合并到 <代码>开发。内容将是相同的,但现在 develop 将不再位于 main 后面。这还有一个额外的优点,即可以在部署之前更轻松地确定任何 release 分支是否与 main 完全同步;您只需确保 master 指向的提交也在 release 中。

This is completely fine, and expected in certain situations. Let's walk through what happened:

  1. You created branch release from the tip of develop. At this moment develop and release are identical.
  2. You add some commits with bug fixes to release (or not, it doesn't actually change the outcome for the purposes of this question).
  3. Once you're happy with release, you deploy it and merge it into main using the --no-ff (no fast-forward) flag. This creates a new merge commit on main. So at this moment release and main have identical contents, but main has one extra commit on it.
  4. Now you also merge release back down into develop, also using --no-ff. This creates a new commit on develop that isn't on release or main.
  5. Now you delete release.

So at this point, develop has at least 1 commit on it that isn't on main, and main has exactly one commit on it that isn't in develop. Presumably you didn't add any commits to develop since creating the release branch, and therefore develop would be exactly 1 commit ahead of main, and exactly 1 commit behind main.

Note: the next time you do a release branch the same process will occur, but you will end up with 2 commits on main that aren't in develop, and this will continue incrementing until you do your first hotfix branch, which will bring all of those older merge commits back into develop all in one shot. This is expected, but can be confusing the first time you see it.

Tip: After experiencing the hotfix branch bringing many merge commits back into develop, now when I work in repos that use Git Flow, after merging release into main, I prefer to merge main into develop rather than release into develop. The contents will be identical, but now develop won't be behind main anymore. This also has the added advantage of making it easier to determine if any release branch is fully up to date with main before you deploy it; you simply need to make sure the commit master points to is also in release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文