創(chuàng)建并管理工作空間
worktree 命令主要用于管理附屬于同一倉庫的多個工作區(qū),詳細說明見:官網(wǎng)參考文檔。
例如,一個倉庫有兩個分支:
feature用于管理代碼feature_doc用于管理文檔
我們可能會在修改代碼的同時也會修改相應的文檔,但我們又不相頻繁的切換分支。就可使用 worktree 命令將兩個分支都檢出到一個目錄下。方便修改代碼和文檔。
創(chuàng)建工作空間
-
克隆祼倉庫,將倉庫祼克隆到
th-ise130-i/.git目錄下TGL233@TGL-ThinkPad MINGW32 ~/Desktop $ git clone --bare <被克隆的倉庫地址> ./th-ise130-i/.git Cloning into bare repository './th-ise130-i/.git'... remote: Enumerating objects: 502, done. remote: Counting objects: 100% (502/502), done. remote: Compressing objects: 100% (336/336), done. remote: Total 3555 (delta 193), reused 416 (delta 148), pack-reused 3053 Receiving objects: 100% (3555/3555), 253.24 MiB | 2.26 MiB/s, done. Resolving deltas: 100% (1576/1576), done. -
將
feature分支檢出到th-ise130-i/feature目錄TGL233@TGL-ThinkPad MINGW32 ~/Desktop/th-ise130-i (main) $ git worktree add --checkout feature feature Preparing worktree (checking out 'feature') HEAD is now at 82c2cd7 2024年09月13日 17:01:51 -
將
feature_doc分支檢出到th-ise130-i/feature_doc目錄TGL233@TGL-ThinkPad MINGW32 ~/Desktop/th-ise130-i (main) $ git worktree add --checkout feature_doc feature_doc Preparing worktree (checking out 'feature_doc') HEAD is now at e633fe7 temp 2024年09月13日 17:05:47
當前目錄結構:
TGL233@TGL-ThinkPad MINGW32 ~/Desktop
$ tree -L 1 -a ./th-ise130-i
./th-ise130-i
├── .git ---> 祼倉庫
├── feature ---> feature 分支工作目錄
└── feature_doc ---> feature_doc 分支工作目錄
3 directories, 0 files
管理工作空間
-
查看當前工作目錄
TGL233@TGL-ThinkPad MINGW32 ~/Desktop/th-ise130-i (main) $ git worktree list C:/Users/TGL233/Desktop/th-ise130-i (bare) C:/Users/TGL233/Desktop/th-ise130-i/feature 82c2cd7 [feature] C:/Users/TGL233/Desktop/th-ise130-i/feature_doc e633fe7 [feature_doc]
浙公網(wǎng)安備 33010602011771號