我一直在尝试
git worktree
并发现一些奇怪的问题。也许它必须将存储库克隆为 --bare
。
$ cd ~
$ git clone --bare https://github.com/actions/checkout.git
签出存储库有一个名为
origin
的遥控器:
$ git remote -v
origin https://github.com/actions/checkout.git (fetch)
origin https://github.com/actions/checkout.git (push)
在上游项目中,我通常有多个遥控器,我喜欢通过执行
git log origin/main
来查看每个遥控器的日志。
让我们在裸存储库中执行此操作:
$ cd ~/checkout.git
$ git log origin/main
fatal: ambiguous argument 'origin/main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
这是为什么?
即使我为修补程序创建工作树,我也会遇到相同的错误:
$ cd ~/checkout.git
$ git worktree add -b hotfix ~/checkout.git/hotfix main
$ cd ~/checkout.git/hotfix
$ git log origin/main
fatal: ambiguous argument 'origin/main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
在帮助中添加
--
分隔符也没有帮助:
$ git log origin/main --
fatal: bad revision 'origin/main'
谢谢@matt 的评论。他们很有帮助。
我不知道这是否是人们应该使用工作树的方式,但如果我想为基于
origin/main
的修补程序创建工作树并使用真正的远程分支符号origin/main
我可以这样做.
$ git clone https://github.com/actions/checkout.git
$ cd checkout
$ git worktree add -b hotfix ../checkout-hotfix origin/main
$ git worktree list
$ git worktree list
/home/kwk/checkout 72f2cec [main]
/home/kwk/checkout-hotfix 72f2cec [hotfix]
这解决了我的问题。