linux - 如何使用git命名空间 stash 分支

标签 linux git github version-control command-line-interface

背景

我正在与一个使用 的大型团队合作用于版本控制。正常流程是:

  • 人们从“积压队列”中选择工单。
  • 通过本地分支机构解决问题(即 git checkout -b my_feature_branch)。
  • 进行多次提交(即 git commit)。
  • 将本地更改推送到远程分支以“备份”他们的工作,以便它存在于多台机器上,以防笔记本电脑损坏或被盗(即 git push -u origin my_feature_branch ).
  • 最终在我们的私有(private) 上创建代码审查页面,并执行从功能分支到 master 的压缩 merge 。

除了员工根据需要创建的远程功能分支外,我们还有几十个发布分支用于创建我们交付给客户的“黄金版本”,即 1.00 , 1.01, 2.00, 2.01, 2.02


问题

一些开发者开始提示分支太多,我倾向于同意。一些开发人员在不再需要旧分支时没有认真清理它们(尽管 在代码审查完成后为此提供了一键删除功能)。


问题

有没有办法配置我们公司部署,以便当人们通过 CLI 使用 git branch 时:

  • 只出现我们的“important/release/gold”分支。
  • 一次性开发人员(临时)分支仅通过 git branch -a 出现?

这样做的主要目标是减少困惑。

编辑: I found a similar question ,但唯一的答案根本不适用(不要使用远程分支),这违反了我允许人们将推送到远程分支作为一种数据备份形式的关键约束。正如@Mort 所暗示的那样,私有(private)命名空间 的概念似乎正是我正在寻找的。现在,我该如何实现?

最佳答案

长话短说:可以 - 但可能有点棘手。

您应该使用 namespace 概念(在这里查看:gitnamespaces)

引用自文档:

Git supports dividing the refs of a single repository into multiple namespaces, each of which has its own branches, tags, and HEAD. Git can expose each namespace as an independent repository to pull from and push to, while sharing the object store

Storing multiple repositories as namespaces of a single repository avoids storing duplicate copies of the same objects, such as when storing multiple branches of the same source.


要激活命名空间,您可以简单地:

export GIT_NAMESPACE=foo

git --namespace=foo clone/pull/push

当命名空间处于事件状态时,通过 git remote show origin 您只能看到在当前命名空间中创建的远程分支。如果停用它(unset GIT_NAMESPACE),您将再次看到主要的远程分支。


在您的情况下可能的工作流程可能是:

创建一个功能分支并处理它

export GIT_NAMESPACE=foo
git checkout -b feature_branch
# ... do the work ...
git commit -a -m "Fixed my ticket from backlog"
git push origin feature_branch # (will push into the namespace and create the branch there)

merge 上游

unset GIT_NAMESPACE
git checkout master
git pull (just to have the latest version)
git merge --squash --allow-unrelated-histories feature_branch
git commit -a -m "Merged feature from backlog"
git push # (will push into the main refs)

棘手的部分

命名空间提供了分支的完全隔离,但你需要每次激活和停用命名空间

注意

推的时候要注意。 Git 将 push 当前命名空间。如果您在功能分支中工作并且忘记激活命名空间,则在推送时,您将在主引用中创建功能分支。

关于linux - 如何使用git命名空间 stash 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854505/

相关文章:

git - 为什么忽略的文件没有被忽略?

Maven 发布插件 : Permission denied (publickey) Github

php - popen 只返回部分输出

c# - Blazor : Change image src with @Onclick without js

Linux - 将系统日期与文件中的日期进行比较并发送电子邮件给管理员

linux - Git 找不到存储库

git - 像 gitignore 但不是 git ignore

python - 使用Python Paramiko在后台运行远程SSH服务器的过程

git - 在 Gerrit 中,我如何将多个评论压缩为一个评论

javascript - meteor JS : Installing on apache/linux server