簡體   English   中英

在容器中掛載git分支

[英]Mount git branches in a container

我有一個帶有2個不同分支的git存儲庫,例如masterfoo

mkdir test && cd test
git init
echo master > master
git add . && git commit -m "init master"
git checkout -b foo
rm master
echo foo > foo
git add . && git commit -m "init foo"

現在,我想將masterfoo作為單獨的卷安裝在一個容器中,以便在我的容器中使用此體系結構:

.
├── foo
│   └── foo
└── master
    └── master

可能嗎?

您可以使用兩個git工作樹 工作樹允許您在不同的路徑中簽出多個分支。

$ git status
On branch master
…
$ git worktree add ../develop
Preparing ../develop (identifier develop)
HEAD is now at fbbbc04 netcat6 for gnks
$ git -C ../develop status
On branch develop
nothing to commit, working tree clean

然后將這些目錄掛載到您的容器中。

您需要兩個克隆,一個克隆已檢出master ,一個克隆已檢出foo 它們可以是淺克隆,以節省空間。

git clone file:///full/path/to/the/repo --depth 1 --branch master master
git clone file:///full/path/to/the/repo --depth 1 --branch foo foo

在VM內只有一個克隆並像普通的git克隆一樣使用它可能更有意義。

我不相信您可以按原樣安裝git branch。 但是,如果Schern的答案還不夠(您可能希望擁有一個公共存儲庫和兩個工作目錄),那么我建議您這樣做: https : //git-scm.com/docs/git-worktree

這樣,兩個目錄將共享相同的.git目錄(一個將是git在另一個目錄中的指令)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM