指定git pull的目录(不是当前目录)

时间:2015-06-18 20:03:29

标签: git

我想从git更新我现有的结帐,但不在该目录内:

-sh-3.2$ pwd
/var/lib/gitolite
-sh-3.2$ git clone repositories/visits.git/
Cloning into 'visits'...
done.
-sh-3.2$ cd visits/
-sh-3.2$ git remote -v
origin  /var/lib/gitolite/repositories/visits.git/ (fetch)
origin  /var/lib/gitolite/repositories/visits.git/ (push)
-sh-3.2$ cd
-sh-3.2$ git --git-dir=/var/lib/gitolite/repositories/visits.git/ --work-tree=/var/lib/gitolite/visits/ pull 
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
-sh-3.2$ cd visits/
-sh-3.2$ git pull
Already up-to-date.
-sh-3.2$ git --version
git version 1.8.2.1
-sh-3.2$ 

我真的不明白git-dirwork-tree,有人可以解释我做错了什么吗?

1 个答案:

答案 0 :(得分:7)

git-dir应指向本地副本的.git文件夹(您的文件指向您克隆的远程存储库):

示例:

~/tmp> git clone repositories/my-project.git/
Cloning into 'my-project'...
done.
~/tmp> git --git-dir=/Users/jhoffmann/tmp/my-project/.git \
> --work-tree=/Users/jhoffmann/tmp/my-project/ pull
Already up-to-date.

Git version 1.8.5介绍-C,将其简化为:

~/tmp> git -C /Users/jhoffmann/tmp/my-project/ pull
Already up-to-date.

(摘自this answer