博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

创建并管理工作空间

Posted on 2024-09-27 13:16  TGL233  阅读(41)  评论(0)    收藏  举报

创建并管理工作空间

worktree 命令主要用于管理附属于同一仓库的多个工作区,详细说明见:官网参考文档

例如,一个仓库有两个分支:

  1. feature 用于管理代码
  2. feature_doc 用于管理文档

我们可能会在修改代码的同时也会修改相应的文档,但我们又不相频繁的切换分支。就可使用 worktree 命令将两个分支都检出到一个目录下。方便修改代码和文档。

创建工作空间

  1. 克隆祼仓库,将仓库祼克隆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.
    
  2. 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
    
  3. 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

管理工作空间

  1. 查看当前工作目录

    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]