Skip to content

Instantly share code, notes, and snippets.

@ryancrum
ryancrum / add-file-to-git.sh
Created March 4, 2013 22:12
Add file to git history
#!/bin/bash
# adds a file to all commits in a git repository, as if it had always been there
# first arg is the path to the file to add
# second arg is relative path within the repository where the file should go
# this is much faster than `git filter-branch --tree-filter 'cp /path/to/file repo/path && git add repo/path' -- --all
cat $1 > /tmp/file-to-add
git filter-branch --index-filter "cat /tmp/file-to-add | git hash-object -w --stdin | xargs -L 1 -I X git update-index --add --cacheinfo 100644 X $2" --tag-name-filter cat -- --all