- Clone the repo.
- Filter out all but one file.
Cloning can usually be done using git clone . This will work in a directory like git clone /path/to/the/repo . Then delete the deleted pointer back to the clone.
git clone /path/to/the/repo git remote rm origin
Then use git filter-branch to filter out all but one file. This is easiest to do with an index filter that deletes all files and then restores only one.
git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- YOURFILENAME
The index filter works by checking every single commit with all changes made. You execute this command and then confirm it. First, it removes all changes from the stage, then restores this single file in its state in this commit. $GIT_COMMIT is a rewrite of a commit. YOURFILENAME is the file you want to save.
If you do all branches and tags using --all , add a tag filter that ensures that the tags are overwritten. It is as simple as --tag-name-filter cat . It will not change the content of tags, but it will ensure that they are moved to overwritten commits.
Finally, you will want --prune-empty delete all empty entries that are not associated with this file. There will be many of them.
All together here.
git filter-branch \ --index-filter 'git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- YOURFILENAME' \ --tag-name-filter cat --prune-empty \ -- --all
source share