Reputation: 1725
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.
Upvotes: 36
Views: 11844
Reputation: 1191
Here is two useful alias: FindFile ff
and FindFilewithCopies ffc
:
# Find if one file ever had into repository
ff = "!git log --pretty=format: --name-status --all -M -B | sort -u | grep $1 #"
# The same as above but showing copied files
ffc = "!git log --pretty=format: --name-status --all -C -M -B | sort -u | grep $1 #"
You get information about file names and operations with them.
Sample use:
$ git ff create
A database/migrations/2014_10_12_000000_create_users_table.php
A database/migrations/2014_10_12_100000_create_password_resets_table.php
A database/migrations/2015_05_11_200932_create_boletin_table.php
A database/migrations/2015_05_15_133500_create_usuarios_table.php
D database/migrations/2015_05_12_000000_create_users_table.php
M database/migrations/2015_05_11_200932_create_boletin_table.php
R051 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_12_000000_create_users_table.php
$ git ffc create
A database/migrations/2014_10_12_000000_create_users_table.php
A database/migrations/2014_10_12_100000_create_password_resets_table.php
A database/migrations/2015_05_11_200932_create_boletin_table.php
A database/migrations/2015_05_15_133500_create_usuarios_table.php
C052 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_11_210246_create_boletin_nosend_table.php
D database/migrations/2015_05_12_000000_create_users_table.php
M database/migrations/2015_05_11_200932_create_boletin_table.php
R051 database/migrations/2014_10_12_000000_create_users_table.php database/migrations/2015_05_12_000000_create_users_table.php
(Posible duplicated from: List all the files that ever existed in a Git repository)
Upvotes: 1
Reputation: 301087
Simplest would be git log --all -- x/y/fubar
- if the file was there, it would have give at least one log entry.
Upvotes: 43
Reputation: 1542
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.
Upvotes: 13