我如何在提交范围之间列出作者之间的所有修改过的文件,但只能列出Git中文件发生的最后一件事情? [英] How can I list all modified files by an author between a commit range but only with the last thing that happened to the file in Git?

查看:120
本文介绍了我如何在提交范围之间列出作者之间的所有修改过的文件,但只能列出Git中文件发生的最后一件事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令:

  git log --oneline --name-status 
--author = $ AUTHOR $ COMMIT_RANGE | grep -vE'[a-fA-F0-9] {5}'
|排序| uniq | cat -n

返回作者在一系列具有状态的提交之间修改的文件列表例如 M 用于修改。

  1 M a_file 
2 M another_file
3 M文件
4 D文件

如何只显示文件文件发生的最后一件事,例如这里被删除了( D )?



我不希望看到之前对该文件的修改(即 M ),只有最后一个修改发生在那个提交范围内的事情。



感谢您的关注!

解决方案
  git log --oneline --name-状态--author = $ AUTHOR $ COMMIT_RANGE | \ 
grep -vE'[a-fA-F0-9] {5}'| cat -n | sed -e's / / / g'| sed -e's / ^ * // g'| \
sort -k 3,3 -k 1n,1n | uniq -f 2 | sed -e's / ^ [0-9] \ {1,\} //'| cat -n

其中 $ AUTHOR 是作者姓名和$ COMMIT_RANGE是一个 OLDER_COMMIT_SHA1..NEWER_COMMIT_SHA1 格式的提交范围(HEAD也可用于NEWER_COMMIT_SHA1)。



命令解释:


  1. 首先从 git log > grep -vE 的输出,我为每行添加 cat -n ;

  2. 在使用 - name-status 时插入TAB git ,插入的起始空格 cat -n with sed -e's / / / g'| sed -e's / ^ * // g';

  3. 然后我先按第三列排序,相同的文件名相邻的行(我按文件名排序);之后我按照第一列的数字排序( cat -n 结果)。通过这种方式,我保留了第一次出现的文件名,这是我感兴趣的文件名;
  4. 之后,是时候让唯一行忽略前2列(因此只需比较文件名)。这样 uniq 将首先返回新文件名的第一次出现,并且不会重复出现相同文件名的其他出现;但同时每个'group'的第一个文件名是我感兴趣的,因为它有最后一个我感兴趣的 - name-status 标志。它告诉我该文件上发生的最后一件事是什么(它是一种修改?删除?等等);
  5. 然后我只是删除计数,因为我需要重新计数 uniq 命令之后的其余行再次计数。我想要感谢 codeWizard Arne VonC $ c> uniq -f 建议,帮助我找出解决方案。


    The command:

     git log --oneline --name-status 
             --author=$AUTHOR $COMMIT_RANGE | grep -vE '[a-fA-F0-9]{5} ' 
             | sort | uniq | cat -n
    

    Returns a list of the files modified by an author between a range of commits with the status e.g. M for modified.

     1  M   a_file
     2  M   another_file
     3  M   file
     4  D   file
    

    How can I show only the last thing that happened to the file file, e.g. here it was deleted (D)?

    I don't want to see the previous modifications to the file (i.e. the M), only the last thing that happened in that range of commits.

    Thanks for the attention!

    解决方案

    This is the command I ended up with which works for me:

    git log --oneline --name-status --author=$AUTHOR $COMMIT_RANGE | \
     grep -vE '[a-fA-F0-9]{5}' | cat -n | sed -e 's/     / /g' | sed -e 's/^  *//g' | \
     sort -k 3,3 -k 1n,1n | uniq -f 2 | sed -e 's/^[0-9]\{1,\} //' | cat -n
    

    Where $AUTHOR is the author name and $COMMIT_RANGE is a range of commits in the form OLDER_COMMIT_SHA1..NEWER_COMMIT_SHA1 (HEAD can be used too for NEWER_COMMIT_SHA1).

    Command explanation:

    1. First after removing the unwanted lines from the git log output with grep -vE, I number each line with cat -n;
    2. I remove the TAB git inserts when using --name-status and the initial spaces inserted by cat -n with sed -e 's/ / /g' | sed -e 's/^ *//g';
    3. Then I sort by the third column first so I have the same filenames adjacent line by line (I sort by filename); after that I sort by the first column numerically (the cat -n result). This way I keep the first occurrence of the filename which is the one I'm interesting in;
    4. After that it's time to keep the unique rows ignoring the first 2 columns (therefore only compare the filenames). This way uniq will return the first occurrence of a new filename first an will not repeat the other occurrences of the same filename; but at the same time the first filename for each 'group' is the one I'm interested in because it has the last --name-status flag I'm interested in and it tells me what's the last thing that happened on that file (was it a modification? A deletion? etc...);
    5. Then I just remove the count because I need to recount the remaining rows after the uniq command and count again.

    I want to thank codeWizard, Arne and VonC for the uniq -f advice which helped me to work out the solution.

    这篇关于我如何在提交范围之间列出作者之间的所有修改过的文件,但只能列出Git中文件发生的最后一件事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆