【发布时间】:2014-08-25 04:56:38
【问题描述】:
我有一个有趣的用例,我想通过GitLab 共享存储库——但是我们公司每个用户的存储库有限,所以我必须通过隐私来分配这些存储库(即,而不是存储库1 用于项目 1,我有项目 1 和 2 → repo 1 用于团队 1,项目 3 和 4 → repo 2 用于团队 2)。
最初我打算在分支名称中创建伪命名空间,例如project1-branch1、project2-branch1、project2-branch2 — 但是我随后了解到 git 包含 namespace 功能,该功能应该在共享一个对象存储时分隔不同的引用命名空间。我试图通过将不同的分支提交到不同的命名空间来在本地对此进行测试,但是我仍然在任何(或没有!)命名空间中看到所有分支:
$ git init .
Initialized empty Git repository in ~/tmp/test/.git/
$ git --namespace test1 checkout --orphan test1
Switched to a new branch 'test1'
$ touch test1
$ git --namespace test1 add -- test1
$ git --namespace test1 commit -m test1
[test1 (root-commit) 27f9d70] test1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1
$ git --namespace test2 checkout --orphan test2
Switched to a new branch 'test2'
$ touch test2
$ git --namespace test2 add -- test2
$ git --namespace test2 commit -m test2
[test2 (root-commit) 4f0f7c5] test2
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1
create mode 100644 test2
$ git log --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:39 2014 -0500
test2
$ git log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:39 2014 -0500
test2
* commit 27f9d703758ae401eb77e7e15d75ac863f296291
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:17 2014 -0500
test1
$ git --namespace test1 log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:39 2014 -0500
test2
* commit 27f9d703758ae401eb77e7e15d75ac863f296291
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:17 2014 -0500
test1
$ git --namespace test2 log --all --graph
* commit 4f0f7c555d3c607d97829263a30170cc431c1d01
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:39 2014 -0500
test2
* commit 27f9d703758ae401eb77e7e15d75ac863f296291
Author: RubyTuesdayDONO
Date: Thu Jul 3 16:06:17 2014 -0500
test1
# separate namespace should prevent conflict (but doesn't)
$ git --namespace test3 checkout --orphan test1
fatal: A branch named 'test1' already exists.
# should include refs/namespaces (but doesn't)
$ tree -a
.
├── .git
│ ├── COMMIT_EDITMSG
│ ├── config
│ ├── description
│ ├── HEAD
│ ├── hooks
│ ├── index
│ ├── info
│ │ └── exclude
│ ├── logs
│ │ ├── HEAD
│ │ └── refs
│ │ └── heads
│ │ ├── test1
│ │ └── test2
│ ├── objects
│ │ ├── 18
│ │ │ └── c152442134ca652c83b111b6063c9b75f9157c
│ │ ├── 27
│ │ │ └── f9d703758ae401eb77e7e15d75ac863f296291
│ │ ├── 4f
│ │ │ └── 0f7c555d3c607d97829263a30170cc431c1d01
│ │ ├── e0
│ │ │ └── f402da78bd414bdd926713d2b54c246432adc5
│ │ ├── e6
│ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│ │ ├── info
│ │ └── pack
│ └── refs
│ ├── heads
│ │ ├── test1
│ │ └── test2
│ └── tags
├── test1
└── test2
17 directories, 27 files
在推送到远程仓库之前是否无法在本地查看命名空间?或者如果它可以在本地使用 git-remote-ext 魔术,如 git clone ext::'git --namespace=foo %s /tmp/prefixed.git',那么为什么不简单地使用 git --namespace ordinary-git-command?
如果我误解了 git 命名空间的目的,请提前抱歉——我只是想在与我的同事分享之前确信这将起作用,否则我只会使用分支名称作为一种伪命名空间(不太优雅,但它会工作)。我已经查看了以下帖子,但并没有真正了解 git 命名空间的功能:
【问题讨论】:
-
不清楚,为什么要在同一个代码库上共享项目 1 和 2?
-
Gitlab 有一个工作组的概念和用户的角色,为什么你不能在你的上下文中应用?
-
虽然我可以承认我的用例被误导了,但我仍然想了解如何在本地分离 gitref 命名空间,如果可能的话——如果不是,为什么,因为 git 具有声称的命名空间功能做到这一点。
标签: git version-control namespaces gitlab collaboration