您好我在git中使用这些脚本进行关键字扩展:https://github.com/turon/git-rcs-keywords/blob/master/.git_filters/rcs-keywords.smudge
涂抹脚本如下所示:
#!/usr/bin/perl
#
$path = shift;
$path =~ /.*\/(.*)/;
$filename = $1;
if (0 == length($filename)) {
$filename = $path;
}
# Need to grab filename and to use git log for this to be accurate.
$rev = `git log -- $path | head -n 3`;
$rev =~ /^Author:\s*(.*)\s*$/m;
$author = $1;
$author =~ /\s*(.*)\s*<.*/;
$name = $1;
$rev =~ /^Date:\s*(.*)\s*$/m;
$date = $1;
$rev =~ /^commit (.*)$/m;
$ident = $1;
while (<STDIN>) {
s/\$Date[^\$]*\$/\$Date: $date \$/;
s/\$Author[^\$]*\$/\$Author: $author \$/;
s/\$Id[^\$]*\$/\$Id: $filename | $date | $name \$/;
s/\$File[^\$]*\$/\$File: $filename \$/;
s/\$Source[^\$]*\$/\$Source: $path \$/;
s/\$Revision[^\$]*\$/\$Revision: $ident \$/;
} continue {
print or die "-p destination: $!\n";
}
像这样的干净脚本:
#!/usr/bin/perl -p
#
s/\$Id[^\$]*\$/\$Id\$/;
s/\$Date[^\$]*\$/\$Date\$/;
s/\$Author[^\$]*\$/\$Author\$/;
s/\$Source[^\$]*\$/\$Source\$/;
s/\$File[^\$]*\$/\$File\$/;
s/\$Revision[^\$]*\$/\$Revision\$/;
应替换关键字的示例文件:
/**
* @file hello.c
* @author @$Author$
* @date @$Date$
* @version @$Revision$
*
* $Id$
*/
int main(int argc, char *argv[])
printf("Hello, new world!");
关键字被相应的数据取代。但是,此数据始终反映我正在切换的提交。不是我要检查的那个
例如,我在分支主服务器中有一个名为hello.c的文件,在分支test_master中有一个 modified hello.c。如果我签出了master,然后检查出test_master,hello.c中的关键字反映了master分支中文件的日期和SHA-1,反之亦然(再次检查master,文件被SHA-1和日期弄脏了of test_master)。
它几乎就像是&#34; git log&#34;在实际检出之前执行涂抹脚本的命令,因此提供了我正在切换的提交的信息。有没有人对此有解释?
我在Windows 7上使用git 2.15
杜德博士