【问题标题】:git pull ignores current work directory in shell scriptgit pull 忽略 shell 脚本中的当前工作目录
【发布时间】:2016-04-30 07:03:30
【问题描述】:

我正在尝试让某种自动部署工作。

我当前的更新后挂钩如下所示:

#!/bin/sh

for ref in $@
do
        if [ $ref = "refs/heads/master" ]
        then
                echo "Deploying $ref to dev-domain"
                cd ~/www/dev-domain
                echo "" > system/lock
                if ! git pull --ff-only
                then
                        echo "Failed to pull"
                        exit
                fi
                if ! system/migrateDatabase
                then
                        echo "Failed to migrate"
                        exit
                fi
                rm system/lock
        fi
done

但我得到的只是:

remote: Deploying refs/heads/master to dev-domain
remote: fatal: Not a git repository: '.'
remote: Failed to pull

不过,文件锁定文件将被放置在正确的位置。

所以,对我来说,git pull 似乎以某种方式忽略了当前工作目录......我该如何解决这个问题? 还是我错过了一些不同的东西?

【问题讨论】:

  • 我忘了说,如果我直接运行命令(在交互式 shell 中),它会按预期工作。

标签: git shell sh git-pull cd


【解决方案1】:

您需要在git pull 之前取消设置GIT_DIR

如果你不这样做,git 会使用 variable GIT_DIR 而不是 PWD。
cd-ing 更改 PWD 而不是 GIT_DIR。

正如Mark Longair 的文章“Missing git hooks documentation”中提到的,GIT_DIR 是由钩子设置的。

在“this answerChris Johnsen 中查看更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 2012-06-06
    • 2012-04-11
    • 2015-09-04
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多