我想使用Git存储库,但工作树应该是远程的.例如:如果我将项目存储在其中~/project
并project.git
存储在其中~/git/project.git
.
我通过配置改变了工作树的内容:
worktree=/Users/myuser/project
而且我能够提交和查看差异,但是当我尝试做的时候git stash
,我收到了错误:
致命的:/ usr/libexec/git-core/git-stash不能在没有工作树的情况下使用.
如何存储.git
远离工作树的目录?为什么我收到这个错误?
git config --get core.worktree
返回正确的工作目录....
dev*_*ole 16
以下似乎工作,根据您的需求调整:
mkdir git
mkdir work
git --git-dir git/test --work-tree work/test init
mkdir work/test
echo -n foo > work/test/foo.txt
git --git-dir git/test status
git --git-dir git/test add foo.txt
git --git-dir git/test commit -m 'commit 1'
Run Code Online (Sandbox Code Playgroud)
编辑:请注意,--work-tree
在存储该值后,您不必在repo初始化之后指定git/test/config
.
你也可以从那里进入工作/测试和提交:
cd work/test
echo -n bar > bar.txt
git --git-dir ../../git/test status
git --git-dir ../../git/test add .
git --git-dir ../../git/test commit -m 'commit 2'
Run Code Online (Sandbox Code Playgroud)
然后使用绝对路径--git-dir
或设置GIT_DIR
.
可以用-C $dir
$ pwd
/home/guanzhang/lede
$ git diff --name-only
feeds.conf.default
$ cd /root/
$ git -C /home/guanzhang/lede diff --name-only
feeds.conf.default
Run Code Online (Sandbox Code Playgroud)
小智 7
--git-dir
标志使用的更正:
使用:
git --git-dir=git/test/.git ...
Run Code Online (Sandbox Code Playgroud)
代替:
git --git-dir git/test ...
Run Code Online (Sandbox Code Playgroud)