2012-09-18 46 views
3

在Git中,你可以克隆一个给定的目录来定目录:的Git拉在“远程”目录

git clone ssh://[email protected]:3687/com/bipper/kids/portal <dir> 

与当我运行我们的构建脚本之一,我想“CD”命令的一些复杂问题的原因采取混帐拉这样的事情:

git pull <dir-to-the-git-folder> 

人体工程学没有执行拉时要在git的文件夹(或取/合并),这样做的时候,是有可能实现某种方式(我上面的例子中没有按” t工作)

+0

+1,有趣的问题。 – greg0ire

回答

3

我想你应该看看git-dir,也许还有work-tree选项。如果您愿意,您也可以使用GIT_DIR/GIT_WORK_TREE变量。

参见手册:

--git-dir=<path> 路径设置为存储库。这也可以通过设置GIT_DIR环境变量来控制。它可以是当前工作目录的绝对路径或相对路径。

-work-tree=<path> 设置工作树的路径。它可以是相对于当前工作目录的绝对路径或路径。这也可以通过设置GIT_WORK_TREE环境变量和core.worktree配置变量来控制(有关更详细的讨论,请参阅git-config(1)中的core.worktree)。

+0

嗯,顺便说一句,想这是我们的Linux服务器上 混帐--git-DIR =/tmp目录/ deployment_1347960691855 - 共同努力树=的/ tmp/deployment_1347960691855拉 但得到 警告:致命的:不是git仓库: '/ tmp目录/ deployment_1347960691855' 但它是一个Git回购 –

+0

当地也试过我的Windows机器上与其他Git项目,我有: C:\> git的--git-DIR = C:\ projectsGit \ bsafe- server --work-tree = C:\ projectsGit \ bsafe-server pull fatal:不是git仓库:'C:\ projectsGit \ bsafe-server' –

+1

也许你应该试试'C:\ projectsGit \ basfe-server \。 git'为git-dir选项...看到这个问题:http:// stackoverflow。com/questions/1386291/git-git-dir-not-working-as-expected虽然... – greg0ire

1

尝试

GIT_DIR=<dir-to-the-git-folder>/.git GIT_WORK_TREE=<dir-to-the-git-folder> git pull 

您也可以分别以--git-dir--work-tree指定这些选项。

man git

--git-dir=<path> 
     Set the path to the repository. This can also be controlled by setting the GIT_DIR environment 
     variable. It can be an absolute path or relative path to current working directory. 

    --work-tree=<path> 
     Set the path to the working tree. It can be an absolute path or a path relative to the current 
     working directory. This can also be controlled by setting the GIT_WORK_TREE environment variable 
     and the core.worktree configuration variable (see core.worktree in git-config(1) for a more 
     detailed discussion). 
1

正如吉特的1.8.5可以使用-C选项更改目录上下文。

sudo -u www-data -H git -C /var/www/ status 

-H将为您的命令设置home-dir。它是可选的,但有用的,当你想避免以下错误:

warning: unable to access '/root/.config/git/attributes': Permission denied 
or 
warning: unable to access '/home/user/.config/git/attributes': Permission denied