Skip to content

Instantly share code, notes, and snippets.

@ap
Created November 21, 2009 14:12
Show Gist options
  • Save ap/240137 to your computer and use it in GitHub Desktop.
Save ap/240137 to your computer and use it in GitHub Desktop.

Storing/Retrieving from the File System

Some projects (the Git project itself for example) store additional files directly in the Git file system without them necessarily being a checked in file.

Let’s start off by storing a random file in Git:

$ echo "Foo" | git hash-object -w --stdin
51fc03a9bb365fae74fd2bf66517b30bf48020cb

At this point the object is in the database, but if you don’t set something up to point to that object it will be garbage collected. The easiest way is to tag it:

$ git tag myfile 51fc03a9bb365fae74fd2bf66517b30bf48020cb

Note that here we’ve used the tag myfile. When we need to retrieve the file we can do it with:

$ git cat-file blob myfile

This can be useful for utility files that developers may need (passwords, gpg keys, etc) but you don’t want to actually check out on to disk every time (particularly in production).

From http://andyjeffries.co.uk/articles/25-tips-for-intermediate-git-users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment