Push just one file to GitHub from a local repository
I have a re开发者_StackOverflow中文版po with multiple scripts. One of them is especially useful and I want to share it using GitHub.
How can I export one file (with commit history) to a GitHub repo without sharing all other scripts from the same repo?
Something like:
git remote add 'origin' git@github.com:user/Project.git
git push -u 'origin' ./useful-script.sh
But how do I specify a single filename? Or should I create some kind of special 'partial' commit?
You'd have to use filter-branch
to rewrite your history and strip everything but that single file:
git filter-branch --index-filter '
git rm --cached -f -r .;
git add ./useful-script.sh;
' --all
should do the job.
If --index-filter
does not work (I'm not sure about that git add
there), try `--tree-filter' with the same argument.
精彩评论