iLemming
iLemming

Reputation: 36166

Retrieving binary file from git

I know, committing binaries into git repo is stupid and generally considered a bad idea, but still:

is it possible to retrieve a binary file to some temp folder from git repo?

I mean of given commit hash?

Upvotes: 1

Views: 1251

Answers (1)

torek
torek

Reputation: 488183

Sure: git checkout will check it out where it belongs, and git show will show it to standard output. So if there's a tag v2.3 that names commit b6636ec88ba0750aec2706865653eb55031fb892 that ultimately contains the file dir1/dir2/image.jpg (which is a binary file), then:

git show v2.3:dir1/dir2/image.jpg > /some/temp/dir/wrongname-wrongext.gif

will put a copy of it in a file with a different name and extension, and:

git checkout b6636ec88ba0750aec2706865653eb55031fb892 -- dir1/dir2/image.jpg

(when run in the repo) will check out the version tagged v2.3 (since v2.3 is just a short name for b6636ec88ba0750aec2706865653eb55031fb892) into your work-dir under its normal path, even if the rest of the work-dir is at some other revision (perhaps a branch tip).

Edit (per comment): note that git checkout of a specific version and path will "write through" the index / staging-area, i.e., will leave the index with the file in changes to be committed state (as shown by git status). If you don't want that, you will probably prefer the git show variant, which does not affect the index.

Upvotes: 2

Related Questions