Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if git has ever tracked file X

Tags:

git

I've tried googling for a solution to this problem but haven't yet found one.

Given a working directory named '/project', I'm trying to find a way of telling if git has ever in the history of the repository tracked a file named '/project/x/y/fubar'.

Is this possible? It seems like the kind of thing that should have an answer already but my google-Fu is failing me this morning.

Edit: possible duplicate at How to tell if a file is git tracked (by shell exit code)?

I don't consider that question the same as this one because the file I'm trying to get information on is not guaranteed to be currently tracked by git, and may not exist in the working dir at calling time. The answers to that question all seem to tell you if the file is currently being tracked by git. Please tell me if I'm wrong and one of those solutions is acceptable for my goal.

like image 276
Jeff Welling Avatar asked Jun 28 '11 11:06

Jeff Welling


2 Answers

Simplest would be git log --all -- x/y/fubar - if the file was there, it would have give atleast one log entry.

like image 162
manojlds Avatar answered Oct 07 '22 18:10

manojlds


A nicer approach would be:

git log --all --pretty=format: --name-only --diff-filter=A | sort - | grep fubar

Merged from a couple of other answers.

like image 9
dch Avatar answered Oct 07 '22 20:10

dch