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, meaning using const on the function is technically correct but semantically wrong. I would like to discuss the semantics with the author who made the change.
Using git, is there a way to find out which revision introduced the "const" token? More specifically, I'd like to know who introduced the token.
"git blame" shows who made the last change to the line, but I would actually like to find the first commit containing the token.
If you want to inspect only specific ranges of lines of a file using git blame, then you can use the -L option.
The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.
Looking up changes for a specific commit If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
There are a few possible ways of doing it.
git blame
, or better graphical blame tool (like git gui blame
or the blame view
in git instaweb
/ gitweb) to browse history of a line, going back in history until
you find appropriate commit.
so called "pickaxe search", i.e. git log -S
with appropriate token / regexp, to find
(list) all commits where number of given tokens changed (which usually means where
given token was added or deleted), e.g.:
git log --reverse -p -S'const int foobar' -- A.cpp
git bisect
where "bad" commit would mean the one with 'const' where there it
shouldn't be (testing using e.g. grep).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With