简体   繁体   English

Git diff - 如何通过“git diff”在两个标签之间获取不同的文件(只有名称)并按文件提交时间排序

[英]Git diff - how to get different files (only name) between two tags by 'git diff' and order by the file commit time

Through the command:通过命令:

$git diff --name-status tag1 tag2 -- target-src

The output is like:输出是这样的:

M       src/config.h
M       src/createTable.sql
A       src/gameserver/BattleGround_10v10.h
M       src/gameserver/CMakeLists.txt
M       src/gameserver/achieve.cpp
M       src/gameserver/achieve.h
A       src/gameserver/action.cpp
A       src/gameserver/action.h
A       src/gameserver/activity.cpp
A       src/gameserver/activity.h
M       src/gameserver/admin.cpp

I got the files that has modified between the two tags.我得到了在两个标签之间修改过的文件。 But I want the list order by committed time.但我希望按提交时间列出列表顺序。 How can I do that?我怎样才能做到这一点?


Thanks to ilius's answer , I added awk for my request:感谢ilius的回答,我为我的请求添加了awk

git diff --name-status tag1 tag2 | while read line ; do
    status=${line:0:1}
    path=${line:2}
    date=$(git log -1 '--pretty=format:%ci' -- "$path")
    echo "$date    $status   $path"
done | sort -r | awk '{print $4" "$5}'

But I think it is too complicated.但我觉得太复杂了。 Can it be simpler?可以简单点吗?

You can try the same thing, but with git log :你可以尝试同样的事情,但使用git log

git log --name-status tag1 tag2 -- target-src

That way, the files are sorted in the order the commits were made.这样,文件按提交的顺序排序。 Also git log has various sorting options you can try out.此外git log有各种排序选项,您可以尝试。

Using mart1n's idea ,使用mart1n 的想法

git log --name-status '--pretty=format:' tag1 tag2 -- target-src | grep -vxh '\s*'

gives a clean output.给出一个干净的输出。

Also try this script:也试试这个脚本:

git diff --name-status tag1 tag2 | while read line ; do
    status=${line:0:1}
    path=${line:2}
    date=$(git log -1 '--pretty=format:%ci' -- "$path")
    echo "$date    $status   $path"
done | sort -r

You can remove the dates (used for sorting) later, I think dates are useful though.您可以稍后删除日期(用于排序),但我认为日期很有用。

You can also remove -r option from sort if you want the older changed files to be on top.如果您希望较旧的更改文件位于顶部,您还可以从sort删除-r选项。

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

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