简体   繁体   中英

Is there a way to see all the versions of a file using git?

I often have a need to find something I coded in an old version of script but I don't know when. I usually try to jump around in the log finding different versions and seeing if they have the change, or I just give up and try something else.

What would be particularly useful is a command that outputs every version of a file between two dates or hashes. Then an easy grep would find what I'm looking for.

It would probably work something like this:

git showeverything d612905a..b39af32e /path/to/file /tmp/output

git has the perfect tool for this: git log -S which will search for a change and only show those commits

# search changes in all branches which touch the string $abc in a file
git log -p -S'$abc' --all -- path/to/file

I understand this may not be the answer you're looking for, but every git hosting website/service has a nice GUI do look through the commit history of every file in a repository. I use it a lot.

You can use git log [commit_range/dates/other_constraints] -- <filename(s)> to show all changelogs pertaining to a specific file, and you can add contraints to the dates/commits/etc. as well.

Use git show <same stuff> to actually show the files at each stage...

git log file shows the commit ids for all commits that affected file .

git show commitid:file prints the contents of the relevant version of the file to stdout.

Note that in the git show command, if you just specify the file name is relative to the root of your git repository unless you specify a path, not to your current directory. To show a file in the current directory:

git show commitid:./file*

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