gpt4 book ai didi

git - git 能找出所有修改过一行代码的作者吗?

转载 作者:太空狗 更新时间:2023-10-29 13:24:43 24 4
gpt4 key购买 nike

我想找出所有更改了一行代码的作者。 Git-log 可以在文件级别进行。我阅读了手册页,似乎 git log 无法在行级别上执行此操作。有没有办法使用 git 命令来执行此操作,或者我需要自己编写一个脚本?

出于我的目的,我想对所有代码行执行此操作。我这样做是为了为我的研究生成作者培训数据。

最佳答案

您想在 git log 上组合 -S--pretty 标志。

来自 git log 手册页,-S 镐搜索:

   -S<string>
Look for differences that introduce or remove an instance of <string>. Note that this is different than the string simply appearing in diff output;
see the pickaxe entry in gitdiffcore(7) for more details.

此标志查找对特定字符串的所有更改。 Using an example from another SO answer, git log -g -Ssearch_for_this 将在历史记录中搜索“search_for_this”的所有更改。

将其与--pretty 结合以获得更好的结果。例如,此命令将在历史记录中搜索对“foo”的更改并返回缩短的散列,然后是作者、两个破折号、消息的第一行、两个破折号和日期:

$ git log -Sfoo --pretty=format:'%h %an -- %s -- %ad'
bc34134 Sally Developer -- Fixed all bugs and made all clients happy forever -- Tue Jan 31 17:41:17 2025 -0500

关于git - git 能找出所有修改过一行代码的作者吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11089004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com