I am currently analysing a Git repo, and am trying to find out how code injected in a certain commit may evolve over time in subsequent commits. For example, given line 9 in commit 57176a..., what is the next commit in the master branch that modifies this line of code?
As far as I know git log
and git blame
work in the other direction: They can analyse a line in a given commit based on previous commits. However, what I would like to do is analyse a line in a given commit based on subsequent commits.
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 .
If you just want to see the diff without committing, use git diff to see unstaged changes, git diff --cached to see changes staged for commit, or git diff HEAD to see both staged and unstaged changes in your working tree.
The --reverse
option for git blame
can help you. If you run this:
git blame -L 9,9 --reverse 57176a..master your_file_name
git will start from the specified commit and search forward in the history until line 9 changes. The output will show you the last commit in which the line was unchanged.
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