简体   繁体   English

多开发人员Git工作流程,保持干净的历史记录

[英]A multi-developer Git workflow, maintaining a clean history

Sandofsky advocates being very strict about your 'main' repo's history, keeping it clean without cluttering it with branches and checkpoint commits. 桑多夫斯基主张对你的“主要”回购历史非常严格,保持干净,不要在分支和检查点提交的情况下混乱。

You should never merge a private branch directly into a public branch with a vanilla merge. 您永远不应该将私有分支直接合并到具有vanilla合并的公共分支中。 First, clean up your branch with tools like reset, rebase, squash merges, and commit amending. 首先,使用重置,rebase,squash合并和提交修改等工具清理分支。

Treat public history as immutable, atomic, and easy to follow. 将公共历史视为不可变的,原子的,易于遵循。 Treat private history as disposable and malleable. 将私人历史视为一次性和可塑性。

This appeals to me, and I was planning on implementing a workflow where my colleagues each have their own remote repository to push to, and do a pull requests when they've finalized work on a branch and cleaned up the commit history. 这对我很有吸引力,我正在计划实现一个工作流程,我的同事们每个人都有自己的远程存储库来推送,并在他们完成分支工作并清理提交历史记录时执行拉取请求。 Subsequently I (the 'integration manager') merge those clean commits into the general development branch. 随后,我(“集成管理器”)将这些干净的提交合并到一般开发分支中。

I guess this approach means that the blessed repo will not have any branches other than the master and develop branch . 我想这种方法意味着受祝福的回购将不会有除主人和开发分支以外任何分支 Feature branches will only exist in your local repository -- if collaboration on a branch is needed, this can happen by pushed the branch to the remote repository of one of the collaborating employees. 功能分支仅存在于本地存储库中 - 如果需要在分支上进行协作,则可以通过将分支推送到其中一个协作员工的远程存储库来实现。

However, the Pro Git book describes this as a workflow for " public small projects". 但是, Pro Git书将此描述为“ 公共小型项目”的工作流程。 Does this mean it's better to use a different workflow in our case, like pushing the finished branches to the blessed repo instead of to a personal repository? 这是否意味着在我们的案例中使用不同的工作流更好,比如将已完成的分支推送到受祝福的仓库而不是个人存储库?

To be clear: I'm not out to add unecessary complexity or overhead. 要明确:我不是要添加不必要的复杂性或开销。 My goal is to establish a workflow where me and my colleagues can work asynchronously, I can review their work when they're done, and bounce it back with comments or merge it into the code base if all is well. 我的目标是建立一个工作流程,让我和我的同事可以异步工作,我可以在完成工作时审查他们的工作,并通过评论将其反弹或将其合并到代码库中(如果一切正常)。


Edit : Apparantly the question asked was not clear, so I'll try to summarize it: 编辑 :显然问的问题不明确,所以我将尝试总结一下:

Would there be a disadvantage in having my colleagues push their branches directly to our blessed repository (eg would it 'pollute' its history in some way)? 让我的同事将他们的分支机构直接推送到我们受祝福的存储库(例如,它会以某种方式'污染'它的历史)会有不利之处吗?

I believe Gitolite 's "personal" branches may suit your needs very well. 我相信Gitolite“个人”分支可能非常适合您的需求。 It is like having a personal area (aka namespace) where each developer can (even forcibly) push. 这就像拥有一个个人区域(即名称空间),每个开发人员都可以(甚至强行)推送。 On the contrary, master is read-only for all developer but an integrator. 相反, master对所有开发人员都是只读的,但是只有集成商。

If Alice's .git/config contains the following configuration: 如果Alice的.git/config包含以下配置:

[remote "origin"]
        url = git@server:project
        push = +refs/heads/*:refs/heads/personal/alice/*
        fetch = +refs/heads/master:refs/remotes/origin/master
        fetch = refs/heads/personal/alice/*:refs/remotes/origin/me/*
        fetch = +refs/heads/personal/bob/*:refs/remotes/origin/bob/*

then Alice would see 然后爱丽丝会看到

  • her branches on the server as origin/me/branch , and 她在服务器上的分支作为origin/me/branch ,和
  • Bob's branches as origin/bob/branch . Bob的分支作为origin/bob/branch

This way, Alice can: 这样,Alice可以:

  • work on her branches and pull/push them to the server 在她的分支上工作并将它们拉/推送到服务器
  • start a new branch off of master master开始一个新的分支
  • start a new branch off of Bob's branches 从Bob的分支机构开始新的分支机构
  • make a backup of her work by simply pushing on the server. 只需按下服务器即可备份她的工作。

Gitolite can be configured such that Alice cannot write on Bob's personal space and vice-versa: 可以配置Gitolite使Alice不能写在Bob的个人空间上,反之亦然:

@users = alice bob
@integrators = john
@repos = repo1 repo2

repo @repos
    RW+                         = @integrators
    RW+     personal/USER/      = @users

我认为没有理由说这个工作流程对你不起作用:强调公众可能是因为对于一个公共项目来说,保持一个干净,不可改变的历史更为重要。

A couple of disadvatages: 一些不满情绪:

The blessed repo will rather quickly (depending on how many developers and features) be cluttered with many branches. 幸运的回购将很快(取决于有多少开发人员和功能)与许多分支混乱。 It's more clean if it only contains eg master and develop, than master, develop, featureA, featureB, featureC .. etc. However you can always clean up the repo by deleting them on the remote (git push origin :featureA) but it adds extra clean up work. 如果它只包含例如master和develop,而不是master,develop,featureA,featureB,featureC等等,它会更干净。但是你总是可以通过在远程(git push origin:featureA)上删除它们来清理repo但它添加了额外的清理工作。

Also, when people fetch from the blessed repo their repos will contain remote references to all those branches and when you remove the remote branches, they will have to "git remote prune origin" off and on to clean up references that are no longer valid, which also adds extra work. 此外,当人们从受祝福的仓库中取货时,他们的仓库将包含对所有这些分支的远程引用,当您移除远程分支时,他们必须关闭“git remote prune origin”以清除不再有效的引用,这也增加了额外的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM