Let\'s say I have a file A.cpp, and I notice an error on line 15 of the file. Let\'s say the error is a \"const\" on a function that returns a pointer to a member variable,
The change may not have always been on line 15 of A.cpp
, so use the surrounding context. Say it was a definition of const int foobar
:
git grep 'const *int *foobar' \
$(git log --reverse --pretty=format:%H -- A.cpp) -- \
A.cpp | head -1
This searches forward in time through all commits on the current branch that touch A.cpp
and finds the first one that contains the offending pattern. The output will be the commit's SHA-1 and the matching line in its revision of A.cpp
.
Once you know the commit, use git show
to learn the author.