gpt4 book ai didi

git log - 查找上次使用的函数

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

有没有一种简单的方法可以找出某个函数在什么时候停止使用?有太多次我发现我认为我正在使用的函数,但似乎没有任何东西在调用它,这让我想知道我何时以及为什么这样做。

最佳答案

git 日志 -S

来自 git log --help:

-S<string>

Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file. Intended for the scripter’s use.

It is useful when you’re looking for an exact block of code (like a struct), and want to know the history of that block since it first came into being: use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.

git 日志 --patch | git 日志 -p

这显示了每个提交的差异补丁。行开头的 + 以绿色突出显示,是已添加的行。行开头的 - 以红色突出显示,是已删除的行。

示例:组合在一起:

假设我想知道上次使用 python 函数 subprocess.call() 的时间。我们可以搜索字符串 subprocess\.call\( 作为 -S diff 选项的参数,如下所示:

git log -Ssubprocess\.call\( --patch

git log 的这种使用将显示具有您指定的文本更改的每个提交的日志,并显示每个提交的差异补丁。

奖励:

如果我想知道我是如何使用一个不再有任何调用它的函数的,我会简单地:

text=subprocess\.call\(
git log --patch -S$text | grep -m 10 "$text"

或者如果我想知道它最后一次被特别删除的时间:

text=subprocess\.call\(
git log --patch -S$text | grep -m 1 "^-.*$text"

关于git log - 查找上次使用的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38598099/

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