Paul
Paul

Reputation: 26680

Find a file in git history

How to find when a specific file existed in git history and how long, and how to get all its versions?

I tried

git log --all -- **/thefile.*

and it doesn't output anything.

The command

git --no-pager log --all --full-history --summary > hist.txt

gives me no file names, but rather a commit info.

P.S. I am also using TortoiseGit.

PPS. I tried to use answers from following question: Git: How to search for a deleted file in the project commit history? and they didn't help me. I just want the practical result (an advice that everybody could take as it is and it will work).

Upvotes: 0

Views: 125

Answers (1)

user7154703
user7154703

Reputation:

you can use command git log --follow --oneline <complete file name> it will give you commit number, description. If you remove --oneline, you will get date time also

with commit number you can checkout the file in detached head mode

Update

The output of git log --follow --oneline MyFile.txt is as follows:

fatal: ambiguous argument 'MyFile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

yes, because you haven't given full path name of file, MyFile.txt, it must be from root folder of the git. you can find root folder by git rev-parse --show-toplevel

Upvotes: 1

Related Questions