user-manual: finding commits referencing given file content
Another amusing git exploration example brought up in irc. (Credit to aeruder for the complete solution.) Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
J. Bruce Fields committed
May 19, 2007 at 00:37 UTC
187b0d80dfad2f51df580bffbbc1e7bc2103f6d4
1 file changed
+16
Documentation/user-manual.txt
+16
@@ -921,6 +921,22 @@ echo "git diff --stat --summary -M v$last v$new > ../diffstat-$new"
921
and then he just cut-and-pastes the output commands after verifying that
922
they look OK.
923
924
+Finding commits referencing a file with given content
925
+-----------------------------------------------------
926
+
927
+Somebody hands you a copy of a file, and asks which commits modified a
928
+file such that it contained the given content either before or after the
929
+commit. You can find out with this:
930
+
931
+-------------------------------------------------
932
+$ git log --raw -r --abbrev=40 --pretty=oneline -- filename |
933
+ grep -B 1 `git hash-object filename`
934
+-------------------------------------------------
935
+
936
+Figuring out why this works is left as an exercise to the (advanced)
937
+student. The gitlink:git-log[1], gitlink:git-diff-tree[1], and
938
+gitlink:git-hash-object[1] man pages may prove helpful.
939
+
940
[[Developing-with-git]]
941
Developing with git
942
===================