คำตอบสั้น ๆ :
git log --full-history -- your_file
จะแสดงให้คุณทุกกระทำในประวัติศาสตร์ repo your_file
ของคุณรวมทั้งกระทำผสานที่สัมผัส อันสุดท้าย (บนสุด) คืออันที่ลบไฟล์
คำอธิบายบางอย่าง:
--full-history
ธงนี่เป็นสิ่งสำคัญ ถ้าไม่มีมัน Git จะทำ "การทำให้เข้าใจง่ายประวัติศาสตร์" เมื่อคุณถามถึงบันทึกของไฟล์ เอกสารมีรายละเอียดที่ชัดเจนเกี่ยวกับวิธีการทำงานและฉันขาดความพยายามและความกล้าหาญที่จะพยายามหามันออกมาจากซอร์สโค้ด แต่เอกสาร git-logนั้นมีสิ่งต่าง ๆ มากมายที่จะกล่าวถึง:
โหมดเริ่มต้น
ลดความซับซ้อนของประวัติศาสตร์ให้เป็นประวัติที่ง่ายที่สุดที่อธิบายสถานะสุดท้ายของต้นไม้ ง่ายที่สุดเพราะมันตัดกิ่งไม้ด้านข้างบางส่วนถ้าผลลัพธ์สุดท้ายเหมือนกัน (เช่นการรวมกิ่งไม้กับเนื้อหาเดียวกัน)
นี้จะเห็นได้ชัดเกี่ยวกับเมื่อแฟ้มที่มีประวัติที่เราต้องการจะลบตั้งแต่ประวัติศาสตร์ที่ง่ายที่สุดในการอธิบายรัฐสุดท้ายของไฟล์ที่ถูกลบคือไม่มีประวัติ มีความเสี่ยงหรือgit log
ไม่ที่--full-history
จะอ้างว่าไฟล์นั้นไม่เคยถูกสร้างขึ้นมาหรือไม่? น่าเสียดายใช่ นี่คือการสาธิต:
mark@lunchbox:~/example$ git init
Initialised empty Git repository in /home/mark/example/.git/
mark@lunchbox:~/example$ touch foo && git add foo && git commit -m "Added foo"
[master (root-commit) ddff7a7] Added foo
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
mark@lunchbox:~/example$ git checkout -b newbranch
Switched to a new branch 'newbranch'
mark@lunchbox:~/example$ touch bar && git add bar && git commit -m "Added bar"
[newbranch 7f9299a] Added bar
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
mark@lunchbox:~/example$ git checkout master
Switched to branch 'master'
mark@lunchbox:~/example$ git rm foo && git commit -m "Deleted foo"
rm 'foo'
[master 7740344] Deleted foo
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 foo
mark@lunchbox:~/example$ git checkout newbranch
Switched to branch 'newbranch'
mark@lunchbox:~/example$ git rm bar && git commit -m "Deleted bar"
rm 'bar'
[newbranch 873ed35] Deleted bar
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 bar
mark@lunchbox:~/example$ git checkout master
Switched to branch 'master'
mark@lunchbox:~/example$ git merge newbranch
Already up-to-date!
Merge made by the 'recursive' strategy.
mark@lunchbox:~/example$ git log -- foo
commit 77403443a13a93073289f95a782307b1ebc21162
Author: Mark Amery
Date: Tue Jan 12 22:50:50 2016 +0000
Deleted foo
commit ddff7a78068aefb7a4d19c82e718099cf57be694
Author: Mark Amery
Date: Tue Jan 12 22:50:19 2016 +0000
Added foo
mark@lunchbox:~/example$ git log -- bar
mark@lunchbox:~/example$ git log --full-history -- foo
commit 2463e56a21e8ee529a59b63f2c6fcc9914a2b37c
Merge: 7740344 873ed35
Author: Mark Amery
Date: Tue Jan 12 22:51:36 2016 +0000
Merge branch 'newbranch'
commit 77403443a13a93073289f95a782307b1ebc21162
Author: Mark Amery
Date: Tue Jan 12 22:50:50 2016 +0000
Deleted foo
commit ddff7a78068aefb7a4d19c82e718099cf57be694
Author: Mark Amery
Date: Tue Jan 12 22:50:19 2016 +0000
Added foo
mark@lunchbox:~/example$ git log --full-history -- bar
commit 873ed352c5e0f296b26d1582b3b0b2d99e40d37c
Author: Mark Amery
Date: Tue Jan 12 22:51:29 2016 +0000
Deleted bar
commit 7f9299a80cc9114bf9f415e1e9a849f5d02f94ec
Author: Mark Amery
Date: Tue Jan 12 22:50:38 2016 +0000
Added bar
โปรดสังเกตว่าgit log -- bar
เทอร์มินัลดัมพ์ด้านบนส่งผลให้ไม่มีเอาต์พุตอย่างแท้จริง Git คือ "ลดความซับซ้อน" ประวัติศาสตร์ลงในนิยายที่bar
ไม่เคยมีอยู่ git log --full-history -- bar
ในทางกลับกันทำให้เรามีความมุ่งมั่นที่สร้างขึ้นbar
และความมุ่งมั่นที่จะลบมัน
มีความชัดเจน: ปัญหานี้ไม่เพียง แต่ในทางทฤษฎี ฉันดูเอกสารเท่านั้นและค้นพบการ--full-history
ตั้งค่าสถานะเนื่องจากgit log -- some_file
ความล้มเหลวสำหรับฉันในที่เก็บข้อมูลจริงที่ฉันพยายามติดตามไฟล์ที่ถูกลบ การทำให้เข้าใจประวัติบางครั้งอาจมีประโยชน์เมื่อคุณพยายามที่จะเข้าใจว่าไฟล์ที่มีอยู่ในปัจจุบันมาเป็นอย่างไรในปัจจุบัน แต่เมื่อพยายามติดตามการลบไฟล์มันมีแนวโน้มที่จะทำให้คุณสับสนโดยการซ่อนความมุ่งมั่นที่คุณใส่ใจ . ใช้--full-history
แฟล็กสำหรับกรณีการใช้งานนี้เสมอ