[英]How can I find the file that a particular line of code existed within in my commit history?
[英]How do I find out change history of a line of code
git blame
可以用來找出修改了哪些提交,但是我遇到了一種情況,似乎整個文件都是從我無法分辨的地方復制的。
$ git blame a.c
c59f772b (a@google.com 2011-08-25 01:07:44 +0000 1) #include <stdio.h>
c59f772b (a@google.com 2011-08-25 01:07:44 +0000 2)
c59f772b (a@google.com 2011-08-25 01:07:44 +0000 3) int main(int argc, char **argv) {
c59f772b (a@google.com 2011-08-25 01:07:44 +0000 4) void *handle;
c59f772b (a@google.com 2011-08-25 01:07:44 +0000 5) double (*cosine)(double);
...
$ git log c59f772b
commit c59f772bc273e65985236ba665f7a88492a33235
Author: a@google.com
Date: Thu Aug 25 01:07:44 2011 +0000
Cloning a bunch of stuff from the another repository
No changes, as is.
該提交僅與復制代碼有關。 我仍然不知道哪個人真正寫了這段代碼。
我可以列出代碼的更改歷史記錄或類似內容嗎?
瞥見git的力量:)
git blame -M -C -C -C -w
從git help blame
:
-C
除了-M之外,還檢測在同一提交中從其他文件移動或復制的行。 當您重新組織程序並在文件之間四處移動代碼時,這很有用。 兩次給出此選項時,該命令還會在創建文件的提交中從其他文件中查找副本。 給出該選項3次后,該命令還會在任何提交中從其他文件中查找副本。
似乎沒有好辦法,因為您只是從另一個地方復制文件並提交。
如果您知道這些類,則可以使用git commit --author authorname
將幫助您打印所有相關的提交。
Br,蒂姆
如果要顯示對單個文件的更改,並查看文件名更改,請執行以下操作:
git log --stat --follow -- <filename>
現在,要責怪該文件,您必須指定可能不再存在的舊文件名。
git blame <hash_before_move> -- <old_file_name>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.