我如何在本地使用git名称空间?

问题描述 投票:7回答:2

我有一个有趣的用例,其中我想通过GitLab共享存储库-但我们公司的每个用户的存储库都很有限,因此我必须通过私密方式来分配存储库(即,不是回购1对于项目1,我有项目1和2→团队1的存储库,项目3和4→项目2的存储库2)。

最初,我要在分支名称中创建伪命名空间,例如project1-branch1project2-branch1project2-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' magick一起在本地工作,那么为什么不简单地与git --namespace ordinary-git-command一起使用?

预先抱歉,如果我误解了git名称空间的目的,我只是想确保在与同事共享之前可以使用,否则,我只是将分支名称用作一种伪命名空间(不太优雅,但可以使用)。我在不真正了解git名称空间功能的情况下查看了以下帖子:

git version-control namespaces gitlab collaboration
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.