有一个 Git 存储库proj.git,克隆到proj1和proj2。proj1没有工作树,proj2有工作树。
目标:更新a.txt,proj1将更改更新到 中的工作树proj2。
问题:git pull失败proj2并显示错误消息:
fatal: Not a git repository (or any of the parent directories): .git
Run Code Online (Sandbox Code Playgroud)
重现问题:
创建proj.git并proj1:
$ git init --bare proj.git
$ git clone proj.git proj1
$ cd proj1
- edit a.txt: v1
$ git add .
$ git commit -m "v1"
$ git push -u origin master
Run Code Online (Sandbox Code Playgroud)
使用工作树创建proj2:
$ cd ..
$ git clone -n proj.git proj2
$ mkdir proj2_worktree
$ cd proj2
- edit .git/config:
[core]
...
worktree = /path/to/workarea/proj2_worktree
$ git checkout
Run Code Online (Sandbox Code Playgroud)
proj2_worktree包含a.txt,按预期工作。
检查原产地状态proj2:
$ git remote show origin
* remote origin
Fetch URL: /path/to/workarea/proj.git
Push URL: /path/to/workarea/proj.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
Run Code Online (Sandbox Code Playgroud)
尝试引入更改proj2(确实有.git):
$ git pull
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
$ git init
Reinitialized existing Git repository in /path/to/workarea/proj2/.git/
$ git pull
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我的 Git 版本是 Debian 上的 1.7.10.4 / Cygwin 上的 2.1.1。
编辑:
另一个发现:在 中proj2,通常的fetch/merge将作为问题的解决方法:
$ git fetch
$ git merge origin master
Run Code Online (Sandbox Code Playgroud)
但是:仍然,为什么不起作用pull?
设置通常是core.worktree一个.git/config坏主意,因为除非您确切地知道\xe2\x80\x99s 正在发生什么,否则它会引起很多混乱。
如果您的计划是部署存储库的修订版本,/path/to/workarea/proj2_worktree而不在内部包含.git文件夹(这对部署有意义),那么 I\xe2\x80\x99d 建议您直接从裸存储库使用更明确的签出:
git --git-dir=/path/to/proj.git --worktree=/path/to/worktree checkout master\nRun Code Online (Sandbox Code Playgroud)\n\n(或从内部执行命令proj.git,因此您不需要指定\xe2\x80\x99t --git-dir)
至于您的实际问题,这可能是早期版本的 Git 的错误。我\xe2\x80\x99ve发现了一些其他与此相关的 问题,所以如果我上面的建议不能满足您的需要,我\xe2\x80\x99d建议您更新您的Git版本。毕竟,1.7.10.4 已经快三年了。
\n