How to find a Git branch containing changes to a given file

Working on many separate enhancements.. How to find which branch my changes to a particular file are on? And if a file was deleted, how can I find that?

Luckily, Git can help us!

We will use git log which is a powerful tool for viewing & searching the commit history of your repository (the log).

To find changes on any branch to your particular file:

git log --all --source -- path/to/my/file 

Git can also find in which commit a file was deleted. Notice that we can use an exact path, or wildcards including a path wildcard.

git log --all --diff-filter=D -- path/to/my/file
git log --all --diff-filter=D -- **/somefile.*

References:
- ‘git log’ documentation
- Stack Overflow: Find a Git branch containing changes to a given file
- Stack Overflow: How to find a deleted file in the project commit history?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>