git 仅推送存储库的一部分
我开发了一些脚本来处理我的 bibtex 数据库和 PDF。
为了方便起见,我在同一个 git 存储库中管理数据库和脚本(我不想更改)。但是,我想让我的脚本可用(例如在 github 上),但不提供我的数据库或 pdf。不过,我希望脚本在 github 和本地都有相同的提交历史记录。
我考虑过拥有一个 github 分支并只推送这个分支。但是,如何使用对主分支中的脚本所做的提交来更新分支呢?
还有其他方法可以做到这一点吗?
I develop some scripts for handling my bibtex-databases and PDFs.
For convenience, I manage both the database and the scripts in the same git repository (a thing I do not want to change). However, I would like to make my scripts available (e.g. on github) but not my database or pdfs. Still, I want to have the same commit-history both on github and locally for the scripts.
I thought about having a github-branch and to push only this branch. But how would I update the branch with the commits done to the scripts in the master branch?
Are there any other ways to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
git subtree
将脚本目录拆分为自己的目录分支(包含该子目录的完整历史记录),然后您可以将其推送到 GitHub。您可以再次运行 git subtree 以使分割存储库保持最新。举个例子,一旦安装了 git subtree ,您就可以执行以下操作:
...假设您的脚本位于 script-directory 和 github-scripts 中 是一个遥控器,指向仅用于脚本的 GitHub 存储库的 URL。
You could use
git subtree
to split off the scripts directory into their own branch (with complete history for that subdirectory) which you can then push to GitHub. You can run git subtree again to keep the split repository up to date.To give an example, once you've installed
git subtree
you can do:... assuming that your scripts are in
script-directory
, andgithub-scripts
is a remote that points to the URL of your GitHub repository intended for just the scripts.Cherry-pick 与脚本相关的提交从
master
进入公共分支。或者,在自己的分支中编辑脚本,然后在需要时将更改合并到master
中。Cherry-pick the commits pertaining to the scripts from
master
into the public branch. Or, edit the scripts in their own branch, then merge the changes intomaster
when you need them.我遵循了@larsmans 给出的建议,结果证明非常方便。
以下是该过程的更多详细信息:
现在,我可以在脚本分支中进行开发,并在数据库需要时与主分支合并。
一个警告:添加两个分支中的新文件后的第一次合并将导致冲突(因为脚本分支是根分支)。因此最好从 master 分支获取脚本并立即提交。
I followed the advice given by @larsmans and it turned out to be very convenient.
Here are some more details for the procedure:
Now I can develop in the scripts-branch and merge with the master branch whenever I need it for my database.
One caveat: The first merge after adding a new file that is in both branches will result in a conflict (because the scripts-branch is a root-branch). So it's best to get the scripts from the master branch and commit them immediately.