git-查找将文件添加到的提交 [英] git - Find commit where file was added

查看:76
本文介绍了git-查找将文件添加到的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个文件 foo.js ,它是在一段时间前提交的。我想让
仅仅找到该文件首次添加的提交。

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


推荐答案

这是更简单的纯Git方法它,不需要管道:

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

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

检查文档。您可以对Deleted,Modified等执行相同的操作。

Check the documentation. You can do the same thing for Deleted, Modified, etc.

https://git-scm.com/docs/git-log#Documentation/git-log.txt---diff-filterACDMRTUXB82308203

我对此有一个方便的别名,因为我总是忘记了它:

I have a handy alias for this, because I always forget it:

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

这很简单:

git whatadded -- foo.js






下面的一行将递归搜索 $ PWD for foo.js ,无需提供文件的绝对路径或相对路径,文件也不需要与 $ PWD


The below one liner will recursively search through sub directories of the $PWD for foo.js without having to supply and absolute or relative path to the file, nor will the file need to be in the same directory as the $PWD

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

这篇关于git-查找将文件添加到的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆