开发者

Push just one file to GitHub from a local repository

开发者 https://www.devze.com 2023-04-08 01:53 出处:网络
I have a re开发者_StackOverflow中文版po with multiple scripts. One of them is especially useful and I want to share it using GitHub.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号