Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See changes applied to specified lines of code in a specified Git commit?

Tags:

git

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.

like image 336
fnakstad Avatar asked Jun 06 '14 07:06

fnakstad


People also ask

How do you see changes in a specific commit?

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 .

How do I see changes not staged for commit?

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.


1 Answers

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.

like image 128
Wally Altman Avatar answered Oct 13 '22 20:10

Wally Altman