lurscher
lurscher

Reputation: 26973

exploring a git repository to find changes affecting specific area

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

Upvotes: 3

Views: 342

Answers (2)

bstpierre
bstpierre

Reputation: 31226

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.

Upvotes: 4

Peter Farmer
Peter Farmer

Reputation: 9380

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.

Upvotes: 4

Related Questions