git - 是否可以从`git push`中排除文件,但将它们保存在本地存储库中? [英] git - Is it possible to exclude file from `git push`, but keep them in the local repository?
问题描述
我想要推送的大多数文件都是一个远程存储库,但有一些我只想将保存在我的本地存储库中(它们包含温和的敏感信息)。
我怎么用git来实现这个功能?我可以配置 .gitignore-for-push
文件吗?我无法使用本地的 .gitignore
文件,因为它会将这些文件完全排除在跟踪之外。
ps:我意识到问题是否有一个排除文件相当于... ,但答案沿着 .gitignore
路径,我不能使用。另一个问题当推...时排除特定的文件...
这是不可能的。如果你已经提交了一个文件,那么它将被推送。推动行为仅对提交起作用,而不是基于文件。
但是,您可以为敏感数据使用子模块,并将此子模块保存在本地计算机上,同时将常规git存储库推送到远程计算机。
In my home directory I have files in a local git repository, because I want track them all under version control.
Most of these files I want to push to a remote repository, but a few I want to keep in my local repository only (they contain mildly sensitive information).
How can I achieve this with git? Can I configure a ".gitignore-for-push
" file? I cannot use the local .gitignore
file, because it would exclude these files completely from being tracked.
ps: I am aware of question Is there an exclude file-equivalent..., but the answer goes down the .gitignore
path which I cannot use. The other question Exclude specific files when pushing... answers only a specific case for git+heroku, not git alone.
This is not possible. If you have committed a file, then it will be pushed. The push action only acts on commits, not on a file basis.
But you could use a submodule for your sensitive data and keep this submodule on your local machine, while you push the regular git repository to the remote machine.
这篇关于git - 是否可以从`git push`中排除文件,但将它们保存在本地存储库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!