Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exploring a git repository to find changes affecting specific area

Tags:

git

i noticed a problem with certain makefiles in my git repository missing a variable definition, and i would like to search in all the commit history to find where my variable TESTDIR occurred in the changeset

How i would do this?

cheers

like image 271
lurscher Avatar asked Apr 21 '26 04:04

lurscher


2 Answers

You can use git log -p FILENAME to show the history of a file, its shows a diff between each version, you should be able to find your change there.

Something like: git log --pretty=format:"%h" -p Makefile gives me an output like this:

$ git log --pretty=format:"%h" -p Makefile
bd45eb7
diff --git a/Makefile b/Makefile
index 58395fa..8bd4e94 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,2 @@
-1
-12
 22
 32

91f610d
diff --git a/Makefile b/Makefile
index d00491f..58395fa 100644
--- a/Makefile
+++ b/Makefile
@@ -1 +1,4 @@
 1
+12
+22
+32

15a8456
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1 @@
+1

If the change is still in your Makefile, you can use git blame to find the revision in which it was put in.

like image 172
Peter Farmer Avatar answered Apr 22 '26 16:04

Peter Farmer


If you use git diff -STESTDIR, it will show you which changesets introduced or removed TESTDIR. From the git-log man page:

-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.

Also look at the --pickaxe-all and --pickaxe-regex that are described just below -S in that man page.

like image 41
bstpierre Avatar answered Apr 22 '26 16:04

bstpierre