2012-08-17 21 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>] 
相關問題