简体   繁体   English

Git diff -name-only 与完整文件路径

[英]Git diff -name-only with full file path

currently using:目前使用:

git diff -name-status

Now this will only give me the following output:现在这只会给我以下输出:

README.md自述文件
created.txt创建.txt
test.txt测试.txt

However I am looking for something more like this:但是我正在寻找更像这样的东西:

/User/github/README.md /用户/github/README.md
/User/github/created.txt /用户/github/created.txt
/User/github/test.txt /用户/github/test.txt

Does anyone know if something like this is possible?有谁知道这样的事情是否可能?

To clarify: the comment from the linked post states: All output will return paths relative to git rev-parse --show-toplevel this is exactly the issue as I would want the path prior to the top level to be included.澄清一下:来自链接帖子的评论指出:所有输出都将返回相对于 git rev-parse --show-toplevel 的路径,这正是问题所在,因为我希望包含顶级之前的路径。

基于 torek 的回答,我能够使用--line-prefix标志在一行中实现这一点:

git diff --name-only --line-prefix=`git rev-parse --show-toplevel`/ HEAD release

Just add the top level yourself:只需自己添加顶级:

git rev-parse --show-toplevel

prints the path to the Git repository.打印 Git 存储库的路径。

Feed the diff --name-only output through, eg, sed -e "s,^,$path," (assuming no commas in your path name):通过例如sed -e "s,^,$path," diff --name-only输出(假设您的路径名中没有逗号):

git-diff-with-abs-path() {
    local path

    path=$(git rev-parse --show-toplevel) &&
    git diff --name-only "$@" | sed "s,^,$path/,"
}

Edit #2: for --name-status , the name comes after a literal tab, so:编辑 #2:对于--name-status ,名称出现在文字选项卡之后,因此:

git-diff-with-abs-path() {
    local path tab=$'\t'

    path=$(git rev-parse --show-toplevel) &&
    git diff --name-status "$@" | sed "s,$tab,$tab$path/,"
}

Fancy this up a bit and you can make it pick --name-only or --name-status out of the $@ part and compute the correct sed expression, rather than hardcoding --name-only or --name-status .稍微想一下,您可以让它从$@部分中选择--name-only--name-status并计算正确的 sed 表达式,而不是硬编码--name-only--name-status

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM