2012-08-17 76 views

回答

3

当某些代码被引入时(见http://git-scm.com/book/en/Git-Tools-Debugging-with-Git),您可以使用git bisect来回溯,并且可以使用这种技术每次检出代码,然后查看该行是否存在。这使得搜索O(log n)的,而不是为O(n),这样可以节省大量的时间...

如果你想知道何时线路编辑最后,您可以使用git blame

+2

有搜索在git的特定字符串的历史的一种方式。其实很简单。查看我的答案以获取更多详情。 – Christopher 2012-08-17 12:25:04

+0

不错!尽管如此,你还是需要知道这条线在第一次引入时的样子(或者至少是其中的一部分)。 – 2012-08-17 12:27:43

+0

绝对如此,但我仍然在我的git工具箱中发现它是最有用的命令之一。 – Christopher 2012-08-17 12:33:31

10

特定的代码行?就像你知道什么线路是提前?当然有可能。其实这很容易。只需使用上git log镐头搜索选项:

-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. 

假设类是public class Foo {,你会发现每一个承诺感动与字符串:

git log -S"public class Foo" 

如果你想将其限制在一个特定的文件,只需使用标准--语法:

git log -S"public class Foo" -- Foo.java 

一般情况下,使用此:

git log -S<string> [-- <file>] 
相关问题