Say I have a file foo.js
that was committed some time ago. I would like to
simply find the commit where this file was first added.
After reading the answers and my own tinkering, this works for me
git log --follow --diff-filter=A --find-renames=40% foo.js
Here's simpler, "pure git" way to do it, no pipeline needed:
Check the docs, you can do the same thing for Deleted, Modified, etc.
I have a handy alias for this because I always forget it:
This makes it as simple as:
The following maybe not is of you interest but i think it will help you in future and is part of debugging ecosystem in Git:
You can use git-blame to show what revision and author last modified each line of a file especifiqly File Annotation, Visit https://git-scm.com/book/en/v2/Git-Tools-Debugging-with-Git
ex. git blame -L 174,190 xx.py