Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何在gitconfig中正确地别名这个git行计数命令?_Windows_Bash_Git_Config_Alias - Fatal编程技术网

Windows 如何在gitconfig中正确地别名这个git行计数命令?

Windows 如何在gitconfig中正确地别名这个git行计数命令?,windows,bash,git,config,alias,Windows,Bash,Git,Config,Alias,我在Stack Overflow上发现了这个命令,用于计算每个用户对回购的LOC贡献: git log --no-merges --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = ""; next } END { for (a in ins) { printf

我在Stack Overflow上发现了这个命令,用于计算每个用户对回购的LOC贡献:

git log --no-merges --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = ""; next } END { for (a in ins) { printf "%10d %10d %10d %s\n", ins[a] - del[a], ins[a], del[a], a } }' | sort -rn
然而,当我尝试在我的.gitconfig中将其别名为命令时,会出现各种各样的错误。我不知道如何正确地转义它,以便在调用git count行时它在bash中正常运行。基于StackOverflow中描述git别名的其他问题,我做了多次尝试,但我一直遇到不同的问题

到目前为止,我已经在gitconfig中尝试了很多东西。这一个给了我最少的错误:

[alias]
    count-lines = "!f() { git log --no-merges --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = \"\"; next } END { for (a in ins) { printf \"%10d %10d %10d %s\n\", ins[a] - del[a], ins[a], del[a], a } }' | sort -rn; }; f"
这就是上面给出的错误:

awk: cmd. line:1: /./ && ... printf "%10d %10d %10d %s
awk: cmd. line:1:                   ^ unterminated string  
awk: cmd. line:1: /./ && ... printf "%10d %10d %10d %s 
awk: cmd. line:1:                   ^ syntax error

据我所知,我在windows 7计算机上,所以我需要在整个命令中使用引号。好的,经过一个半小时的调试和摆弄,我终于解决了问题:我需要在printf语句中的新行字符中转义反斜杠

broken: count-lines = "!f() { git log --no-merges --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = \"\"; next } END { for (a in ins) { printf \"%10d %10d %10d %s\n\", ins[a] - del[a], ins[a], del[a], a } }' | sort -rn; }; f"
fixed:  count-lines = "!f() { git log --no-merges --pretty=format:%an --numstat | awk '/./ && !author { author = $0; next } author { ins[author] += $1; del[author] += $2 } /^$/ { author = \"\"; next } END { for (a in ins) { printf \"%10d %10d %10d %s\\n\", ins[a] - del[a], ins[a], del[a], a } }' | sort -rn; }; f"

只是为了排除shell中的参数替换问题:您能看到git echo aa bb cc使用以下别名给出了什么吗:echo=!f{echo'$1$2$3';};在我的PC bash/linux上,我看到1美元2美元3美元不是aa bbcc@LeGEC我还有1美元2美元3美元你的别名看起来正确。你犯了什么错误?@torek我在问题中发布了错误。我刚刚解决了这个问题,我需要在printf语句中转义换行符。否则,该命令将获得实际的换行符,并且字符串不完整