Find commit where file was added

2019-01-05 07:47发布

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

3条回答
狗以群分
2楼-- · 2019-01-05 08:17
git log --oneline -- foo.js | tail -n 1
查看更多
倾城 Initia
3楼-- · 2019-01-05 08:31

Here's simpler, "pure git" way to do it, no pipeline needed:

git log --diff-filter=A -- foo.js

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:

git config --global alias.whatadded 'log --diff-filter=A'

This makes it as simple as:

git whatadded -- foo.js
查看更多
我只想做你的唯一
4楼-- · 2019-01-05 08:35

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

查看更多
登录 后发表回答