集成器工作流程,fetch-rebase-push 对于远程存储库安全吗?

发布于 2024-08-02 01:00:44 字数 565 浏览 10 评论 0原文

我正在使用集成器工作流程管理 git 存储库。 换句话说,我从同事那里提取提交,并将它们推送到受祝福的存储库。

我希望在大多数情况下保持提交历史记录呈线性,因此在集成更改时可以进行 rebase 而不是 merge 吗? 这是一个示例:

git fetch coworker
git checkout coworker/master
git rebase master
git checkout master
git merge HEAD@{1}
git push

我担心远程存储库在执行下一次 git pull 时会发生什么情况。 git 是否能够处理此问题,或者 coworker 存储库在 pull 期间是否会失败,因为提交在 origin 上的顺序不同>?

更新:我最初的示例是从“master”重新建立“coworker”分支的基础。 我的意图恰恰相反,将“同事”提交置于主提交之上。 所以我更新了这个例子。

I'm managing a git repo using the integrator work flow. In other words, I pull commits from my co-workers, and push them out to the blessed repo.

I'd like to keep the commit history linear for most cases, so is it OK to do a rebase instead of a merge when I integrate changes? Here is an example:

git fetch coworker
git checkout coworker/master
git rebase master
git checkout master
git merge HEAD@{1}
git push

I'm concerned what will happen to the remote repos when they do their next git pull. Will git be able to handle this, or will the coworker repo fail during the pull, now that the commits are in a different order on the origin?

Update: I originally had the example rebase the 'coworker' branch from 'master'. What I intended was the opposite, to put the 'coworker' commits on top of the master. So I updated the example.

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

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

发布评论

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

评论(5

橘亓 2024-08-09 01:00:44

您肯定不想按照您的建议进行操作,它会将 master 分支重新设置为您同事的 master 分支。 根据您同事的 master 的基础,您可能最终会经常倒回中央 master

您可能想做的恰恰相反,在将同事的 master 合并到 master 之前对其进行 rebase。

git fetch coworker
git checkout coworker/master
git rebase master
git checkout master
git merge HEAD@{1}
git push

但我仍然不推荐这个。 您的同事将必须解决您如何重新调整他们的更改的问题。 大多数时候,这可能是微不足道的,他们可以放弃自己的提交来支持你的提交,但这仍然是他们可能需要手动检查的事情。

就我个人而言,我建议直接合并他们的提交。 如果您觉得它们基于太旧的 master 版本,并且合并将变得不必要的复杂或基于不合理的旧提交,那么让他们重新调整其 master 的基础并重新获取。 然后至少他们知道您要合并什么,并且解决代码中的任何冲突。

另外,我要警告不要追求不必要的线性历史。 合并并行开发的开发人员分支可以让您更真实地再现历史。 如果您在合并之前对开发人员的提交进行变基,那么您将不再拥有准确表示该开发人员修复和提交的代码状态的提交记录。 这可能并不常见,但可能会发生两个提交交互产生错误,但不是合并冲突。 如果你不重新设定基准,你就会得到更准确(也更公平!)的“指责”。

You definitely don't want to do what you suggest, it will rebase the master branch onto your coworker's master. Depending on what your coworker's master was based on you may end up often rewinding the central master.

What you might want to do is the opposite, rebase your coworker's master before merging it into master.

git fetch coworker
git checkout coworker/master
git rebase master
git checkout master
git merge HEAD@{1}
git push

I still wouldn't recommend this, though. Your coworkers will have to resolve how you rebased their changes. Most of the time it's probably trivial and they can throw away their commits in favour of yours, but it's still something that they probably need to manually check.

Personally, I would recommend straight merging of their commits. If you feel that they are based on a too old version of master and the merge will be unnecessarily complex or based on an unjustifiably old commit then get them to rebase their master and refetch. Then at least they know what you are merging and they resolve any conflicts in their code.

Also, I would caution against aiming for unnecessarily linear history. Merging in developers' branches developed in parallel gives you a more true representation of history. If you rebase a developer's commit before merging then you no longer have a commit record that is an accurate representation of exactly the state of the code that that developer fixed and submitted. This may not matter very often but it may happen that two commits interact to produce a bug, but not a merge conflict. If you don't rebase, you get a more accurate (and fairer!) 'blame'.

熊抱啵儿 2024-08-09 01:00:44

关于 git 的大量文档和教程中的绝大多数都清楚地表明,rebase 只能在私有分支上使用,而不能被其他人看到。 在你的模型下,我会非常害怕莫名其妙的失败或不得不在其他副本上重复工作。 避免!

The vast majority of the vast amount of documentation and tutorials about git make it clear that rebase should be used only on private branches, never something that someone else can see. Under your model I would be very afraid of inexplicable failures or having to repeat work at other replicas. Avoid!

风吹雪碎 2024-08-09 01:00:44

正如“合并中的休战中提到的vs. rebase war?”文章,(强调我的)

也许传统变基最严重的问题是它阻碍协作
在变基前后从存储库中提取内容的人会遇到冲突,因为这两个历史相互矛盾。 因此,标准警告“不要在已发布的存储库中变基”,可以将其改写为“不要在以后可能想要变基的工作上进行协作”。

即使它因为缺乏冲突而“有效”,如果您必须在 rebase 期间解决任何重要的合并,它也可能会导致一些麻烦:

M0----M1----M2
\
 \
  \
   B1----B2

M0----M1----M2
            \
             \
              \
               B1'---B2'

您的(之前发布的)分支的 SHA-1 被重写,您的同事将有很难将该分支合并到他们的环境中。

As mentioned in the "A truce in the merge vs. rebase war?" article, (emphasis mine)

Perhaps the worst problem with traditional rebasing is that it prevents collaboration.
Somebody who pulls from a repository before and after a rebasing will experience conflicts because the two histories contradict each other. Thus the standard caveat "don't rebase within a published repository", which can be reworded to "don't collaborate on work that you might later want to rebase".

Even if it "works" because of lacks of conflicts, it can lead to some troubles if you have to solve any non-trivial merge during your rebase:

M0----M1----M2
\
 \
  \
   B1----B2

M0----M1----M2
            \
             \
              \
               B1'---B2'

The SHA-1 of your (previously published) branch being rewritten, your colleagues will have a hard time merging that branch in their environment.

回忆躺在深渊里 2024-08-09 01:00:44

对于简单的情况来说,这将是可接受的工作流程。 当您的同事执行 git pull 时,实际上是先执行 git fetch,然后执行 git merge。 Git 非常擅长进行合并,并且能够毫无问题地解决简单的情况。

但是,如果您必须在 git rebase 步骤中执行任何工作来解决冲突,那么您的同事在拉取时可能必须再次执行该工作。 之所以会发生这种情况,是因为在变基之后你的提交顺序看起来与他们的有很大不同。

如果您习惯了非线性历史记录,Git 可能能够更好地管理此工作流程(因为这就是它的设计目的)。

This would be an acceptable workflow for trivial cases. When your coworkers, do a git pull, it's really a git fetch followed by a git merge. Git is really great at doing merges and will be able to resolve simple cases without issue.

However, if you have to do any work to resolve conflicts at the git rebase step, then your coworkers may have to do that work again when they pull. That will happen because your sequence of commits looks a lot different from theirs after the rebase.

If you become comfortable with a nonlinear history, Git will probably be able to manage this workflow better (since that's what it is designed to handle).

︶ ̄淡然 2024-08-09 01:00:44

我对这个工作流程做了一些简单的测试。 我同意查尔斯的帖子,但想添加一些其他信息。

优点

  • 工作流程不会中断用户从您的公共存储库中提取数据。
  • 它使您可以更好地控制拉入主线的提交。
  • 更容易跟踪主线分支的功能历史记录。 如果您必须执行合并提交(标准工作流程)来拉取多个更改,则合并提交会将所有新提交的修改分组到单个提交中。 这打破了“一次提交一项功能”的习惯。

缺点

  • 在您从中提取更改的存储库上,“原始”提交仍然会显示。 这可能会给贡献者带来困惑,除非他们知道您在做什么。 我想解决这个问题的一种方法是让贡献者在拉取并重新设置基础后丢弃他们的开发分支。
  • 如果远程存储库在您变基后没有丢弃它们的开发分支,那么它会使主分支历史记录难以与远程分支一起跟踪。
  • 变基后,您将丢失提交中的原始作者姓名。 (也许有一种手动方法可以解决这个问题。)这使得跟踪谁提交了每个更改变得更加困难。

I did some simple tests on this work flow. I agree with Charles' post, but wanted to add some other info.

Pros

  • The workflow will not break the users pulling from your public repo.
  • It gives you more control over the commits being pulled into your mainline.
  • It is easier to follow the feature history of the mainline branch. If you have to do a merge commit (standard workflow) to pull multiple changes in, then the merge commit will group modifications of all the new commits into a single commit. This breaks the "one commit one feature" idiom.

Cons

  • On the repo where you are pulling changes from, the "original" commits will still show up. This will likely add confusion for the contributor, unless they know what you are doing. I guess one way around this is to have the contributor throw away their dev-branch after you pull and rebase it.
  • If the remote repos don't throw away their dev branches after you rebase, then it makes the master branch history difficult to follow along side the remote branch.
  • After the rebase, you loose the original authors name on the commit. (Maybe there is a manual way around this though.) This makes it harder to track who commited each change.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文