How do I find other commits that touch the same code as a given commit?

Viewed 30

I'm looking to cherry-pick some code. The code was squashed-on-merge, so I know it's just that one commit to get the feature or bugfix that I desire.

However, I'm worried that this commit may introduce its own bugs. Presumably, those bugs were spotted and fixed on the main branch. So I'd like to see a list of future commits in the same branch that touch the same code, to find bugfixes to the main commit. How do I do that?

Quick doodle of commits/branches cherry pick desirted

1 Answers

You can use combinations of git log and git blame to find the information you are looking for. A good first start is to do git blame -- <filename> this will show which commits changed each line of a file. You can also do git log <branch> -- <filename> to see a history of commits that changed a given file. Fore more details check out git help blame and git help log.

Related