我试图将代码备份自动化为git,但收效甚微。在这种情况下,我在perl中尝试它。我目前的问题是git在运行时希望在正确的目录中。 (注意第三行。)我收到错误:致命:无效的refspec' dest = c:\ data \ git \ aperio \ Scratch \ src \ rich' 有没有办法将我的目录定义为arg?或者在指向目录的环境中运行失败?
注意:我认识到这对大多数git命令都是一个问题,而不仅仅是拉动。
...
@file=("deploy*.bat","deploy.ini","product.lic");
system("$gitexe checkout integrate");
system("$gitexe pull url=https://github.com/Aperio/aperio/Scratch/src/rich dest=c:\\data\\git\\aperio\\Scratch\\src\\rich");
exit if ($testing);
my $message="Changed: ";
foreach $file (@file) {
my ($src,$git,$timestamp,$sb,$message);
my @files = glob($file);
foreach my $f (@files) {
$git=$gitdir."\\rich\\".$f;
say $git;
# Update git if needed
if ((stat($git))[9] < (stat($f))[9]) {
$message.="$f, ";
system("robocopy.exe . $gitdir /R:3 /Z /XO $f"); # Copy file to git folder
system("$gitexe add $gitdir\\rich\\$f");
}
}
}
system("$gitexe commit -m $message");
system("$gitexe status");
system("$gitexe push origin ");
答案 0 :(得分:5)
是的,您可以设置the GIT_DIR
environment variable or the --git-dir
option告诉git使用哪个.git
目录。
但是,您最好使用Git.pm之类的内容。
use Git;
my $repo = Git->repository(Directory => '/srv/git/cogito.git');
$repo->command("commit", "-m", $message);
这避免了许多问题,如shell转义,错误处理,捕获输出以及忘记设置--git-dir
。