【问题标题】:Git: Find code in a file's historyGit:在文件历史记录中查找代码
【发布时间】:2013-06-14 15:02:16
【问题描述】:

我想在git的文件历史中查找一个字符串,我知道要在所有文件中找到它是这样的:

git grep whatever $(git rev-list --all) 

但我只想在文件的历史记录中找到它,例如我想知道如何在文件中找到字符串“preg_match”:datacar.php

【问题讨论】:

    标签: git file find history


    【解决方案1】:

    可以使用 the pickaxe

    git log -S preg_match -- datacar.php
    

    如果你想要差异

    git log -p -S preg_match -- datacar.php
    

    更多信息

    -S 寻找引入或删除实例的差异 。请注意,这与字符串不同 出现在差异输出中;查看 gitdiffcore(7) 中的镐条目 更多细节。

    【讨论】:

    • 我做到了,但这是我得到的错误:致命:不明确的参数“DataCarSoaker.php”:未知修订或路径不在工作树中。使用 '--' 将路径与修订分开,如下所示:'git [...] -- [...]'
    猜你喜欢
    • 2010-12-19
    • 2012-08-10
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 2019-05-05
    • 2011-01-06
    相关资源
    最近更新 更多