Skip to content

Instantly share code, notes, and snippets.

@lboulard
Last active March 24, 2022 11:54
Show Gist options
  • Save lboulard/24eb10cbeb16f054eacec3a9eb099b09 to your computer and use it in GitHub Desktop.
Save lboulard/24eb10cbeb16f054eacec3a9eb099b09 to your computer and use it in GitHub Desktop.
Git as carrier

Git as carrier

Using a Git tag

Create a tag tar with file-others content to save.

$ git tag tar "$(tar cf - $(git ls-files -o --exclude-standard) | git hash-object -t blob -w --stdin --no-filters)"

Get back saved content from tag tar:

$ git cat-file blob $(git show-ref -d -s refs/tags/tar || echo "missing") | tar tf -

Using a Git branch

Create or update a branch work with file-others content to save in file work.tar.

$ b="$(tar cf - $(git ls-files -o --exclude-standard) | git hash-object -t blob -w --stdin --no-filters)"
$ t="$(echo -n "100644 blob $b\twork.tar" | git mktree)"
$ p="$(git show-ref -d -s refs/heads/work || true)"
$ h="$(echo "work.tar commit" | git commit-tree ${p:+-p} ${p:+${p}} "$t")"
$ git update-ref refs/heads/work "$h"

Get back saved content from file work.tar from branch work:

$ git cat-file blob work:work.tar | tar tf -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment