2

I recently received a modification of a file of mine that I put under revision control, but I cannot spot on which commit this modified file is based.

So, is there a way to determine which commit modifying a given file is the least different to an edited version?

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221

1 Answers1

1

I don't know of any magical way of checking this but you might want to try this:

git diff --stat HEAD..HEAD~10 -- myfile.cpp

and manually change the HEAD~10

It will tell you how many difference there are between the revisions.

You can automate this using:

for i in {1..5}; do echo "HEAD~$i"; git diff --stat HEAD~$i..HEAD CMakeLists.txt ; done
gvd
  • 1,823
  • 13
  • 18
  • thanks, I can pipe the output of `git-diff --stat` to `grep myfile.cpp | gawk ' { print $3 } '` to reduce that to the amount of changes. I guess together with that for loop one can then use `sort` to obtain the best candidates and review their diffs manually – Tobias Kienzler Dec 15 '11 at 08:08
  • instead of that for loop, you can use `git log --stat myfile.cpp`, and again with some smart `gawk`ing the output might be formatted into something like "commitid howManyChanges" ( I don't know enough about `awk` though) – Tobias Kienzler Dec 15 '11 at 08:12
  • `git log --numstat --oneline -- myfile.cpp` gives a nice and brief output (ok, enough comments added...) – Tobias Kienzler Dec 15 '11 at 08:22