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?

1

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

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
instead of that for loop, you can use git log --stat myfile.cpp, and again with some smart gawking the output might be formatted into something like "commitid howManyChanges" ( I don't know enough about awk though)
git log --numstat --oneline -- myfile.cpp gives a nice and brief output (ok, enough comments added...)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.