简体   繁体   中英

How to find if file is in a git commit history?

I have a version of a program laying around, let's say " mystery.c ". I use git for this program's development.
I don't know which (if any) commit contains this specific version. For instance, I may have generated this version by copying at some intermediate stage between commits for some reason.

How do I ask git to find the most recent commit containing this file's contents exactly?
Or to say that the file's exact content is not in the history?
Or, more generally, to find the most similar recent match in the history?

You can simply use git log :

git log --follow filename

The --follow option is for listing the history of a file beyond renames (works only for a single file).

Compact version:

git log --follow --name-only --format='%H' -- filename

When it comes to find a file content, " Finding Content in Files With Git " is a good read, using combination of git log -S (pickaxe option) and git grep .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM