【问题标题】:Git pull in "remote" directoryGit拉入“远程”目录
【发布时间】:2012-09-10 12:31:54
【问题描述】:

在 Git 中,您可以将给定目录克隆到给定目录:

git clone ssh://gitolite@dev.bipper.com:3687/com/bipper/kids/portal <dir>

当我运行我们的一个构建脚本时,“cd”命令会出现一些复杂问题,我想使用 git pull 如下所示:

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

执行拉取(或获取/合并)时,Ergo 不必在 git 文件夹中,是否有可能以某种方式实现(我上面的示例不起作用)

【问题讨论】:

    标签: git


    【解决方案1】:

    我认为你应该看看git-dirwork-tree 选项。如果您愿意,也可以使用 GIT_DIR / GIT_WORK_TREE 变量。

    查看手册:

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

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

    【讨论】:

    • 嗯,顺便说一句,在我们的 linux 服务器上尝试这个 git --git-dir=/tmp/deployment_1347960691855 --work-tree=/tmp/deployment_1347960691855 pull 但是得到 WARN:fatal: Not a git存储库:'/tmp/deployment_1347960691855' 但它是一个 Git 存储库
    • 还尝试在我的 Windows 机器上本地使用我拥有的另一个 Git 项目:C:\>git --git-dir=C:\projectsGit\bsafe-server --work-tree=C: \projectsGit\bsafe-server pull fatal: Not a git repository: 'C:\projectsGit\bsafe-server'
    • 也许你应该尝试C:\projectsGit\basfe-server\.git 的 git-dir 选项...看到这个问题:stackoverflow.com/questions/1386291/… 不是手册上说的,虽然...
    【解决方案2】:

    试试

    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).
    

    【讨论】:

      【解决方案3】:

      从 git 1.8.5 开始,您可以使用 -C 选项来更改目录上下文。

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

      -H 将为您的命令设置主目录。它是可选的,但在您想避免以下错误时很有用:

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

      【讨论】:

        猜你喜欢
        • 2012-05-13
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 2022-07-11
        • 1970-01-01
        • 1970-01-01
        • 2015-07-03
        • 1970-01-01
        相关资源
        最近更新 更多