简体   繁体   中英

get all historical versions of a file in a git repo

I'd like to retrieve all the historical versions of a file in a git repo, and save them into multiple files. I am thinking of making a script to checkout all the commit tags one by one and save the target file, but is there any easier way to do this? Thanks!

git rev-list --all --objects -- path/to/file.txt

lists you all the blobs associated with the repo path

To get a specific version of a file

git cat-file -p commitid:path/to/file.txt
for file in $(git log --format="%H" --all --follow --name-status   -- <path/to/your/file> | egrep '\w' | perl -pe 's/([0-9a-f]{40})\n/\1/' | perl -pe 's/(.{40}).*\s(\S+)$/\1:\2/'); do git cat-file -p $file > content_of_$(echo $file | cut -c -40); done

This assumes that there are no whitespace characters in you file's names or paths. (There should no be anyway.)

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