Reputation: 7043
How can I check, if a file with the same content is already under git version control?
Upvotes: 1
Views: 88
Reputation: 489808
That seems like a rather odd thing to do (why not just add it?) but:
git cat-file -t $(git hash-object -t blob foo)
will fail or (very unlikely) print something other than blob
if the contents of file foo
are not already in the repo. That gets you part-way; next, you have to find out whether that hash-ID is referenced (i.e., that it is not a dangling blob), and if so, by what references. It might be referenced by the index (only, or in addition to being in some tree in some commit). To see if it's in a tree in a commit, clone the repo to a --bare
clone (if it's not already one) and see if the ID is (still) valid there.
Upvotes: 3