2013-02-27 131 views
2

git blame可用於找出哪個提交已修改,但我遇到了一種情況,看起來整個文件是從我不知道的地方複製過來的。如何找出一行代碼的更改歷史記錄

$ git blame a.c 
c59f772b ([email protected] 2011-08-25 01:07:44 +0000 1) #include <stdio.h> 
c59f772b ([email protected] 2011-08-25 01:07:44 +0000 2) 
c59f772b ([email protected] 2011-08-25 01:07:44 +0000 3) int main(int argc, char **argv) { 
c59f772b ([email protected] 2011-08-25 01:07:44 +0000 4)  void *handle; 
c59f772b ([email protected] 2011-08-25 01:07:44 +0000 5)  double (*cosine)(double); 
... 

$ git log c59f772b 
commit c59f772bc273e65985236ba665f7a88492a33235 
Author: [email protected] 
Date: Thu Aug 25 01:07:44 2011 +0000 

    Cloning a bunch of stuff from the another repository 
    No changes, as is. 

此提交只是關於複製代碼。我仍然不知道是哪個人和誰寫了這段代碼。

我可以列出更改歷史記錄的代碼或類似的東西嗎?

回答

4

概覽在動力即GIT中:)

git blame -M -C -C -C -w 

git help blame

-C

除了-M,檢測線從同一個c中修改過的其他文件移動或複製ommit。當您重新組織程序並在各個文件之間移動代碼時,這非常有用。當這個 選項被賦予兩次時,該命令會另外在創建該文件的提交中查找 中的其他文件的副本。當此選項爲 給定三次時,該命令還會在任何提交中查找 中的其他文件的副本。

0

看來沒有什麼好方法,因爲你只是從另一個副本複製文件並提交它。

如果你知道這些類,你可以使用git的承諾--author AUTHORNAME

將幫助您打印出所有相關的提交。

BR, 添

0

如果你想顯示更改到一個文件,並查看文件名稱更改做到以下幾點:

git log --stat --follow -- <filename> 

我們從以前的時候,你需要指定怪文件舊的文件名稱可能不再存在。

git blame <hash_before_move> -- <old_file_name> 
相關問題