工作树上的Git pull失败:不是git存储库(或任何父目录)

时间:2015-02-15 08:59:44

标签: git

有一个Git存储库proj.git,克隆到proj1proj2proj1没有工作树,proj2有工作树。

目标:更新a.txt中的proj1,将更改更新为proj2中的工作树。

问题:git pullproj2上失败并显示错误消息:

fatal: Not a git repository (or any of the parent directories): .git

重现问题:

创建proj.gitproj1

$ 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

使用worktree创建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

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)

尝试在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

我做错了什么?我的Git版本在Cygwin上的Debian / 2.1.1上是1.7.10.4。

修改

另一个发现:在proj2中,通常fetch / merge将作为问题的解决方法:

$ git fetch
$ git merge origin master

但是,为什么pull不起作用?

1 个答案:

答案 0 :(得分:0)

core.worktree中设置.git/config通常是一个坏主意,因为除非您确切知道发生了什么,否则会造成很多混淆。

如果您的计划是在/path/to/workarea/proj2_worktree部署存储库的修订版而内部没有.git文件夹(这对部署有意义),那么我建议您使用更明确的结帐,直接来自裸存储库:

git --git-dir=/path/to/proj.git --worktree=/path/to/worktree checkout master

(或从proj.git内执行命令,因此您无需指定--git-dir


至于你的实际问题,这可能是早期版本的Git的一个错误。我发现some other questions引用了这个,所以如果我上面的建议不符合你的需要,我建议你更新你的Git版本。毕竟,1.7.10.4几乎三年

相关问题