git - 是否可以从“git push"中排除文件,但将它们保存在本地存储库中? [英] git - Is it possible to exclude file from `git push`, but keep them in the local repository?

查看:24
本文介绍了git - 是否可以从“git push"中排除文件,但将它们保存在本地存储库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主目录中,我在本地 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).

我如何用 git 实现这一目标?我可以配置一个.gitignore-for-push"文件吗?我不能使用本地 .gitignore 文件,因为它会将这些文件完全排除在跟踪之外.

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:我知道问题 有吗一个排除文件等效...,但答案是我无法使用的 .gitignore 路径.另一个问题 推送时排除特定文件... 仅回答 git+heroku 的特定情况,而不是单独的 git.

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.

但是你可以为你的敏感数据使用一个子模块,并将这个子模块保留在你的本地机器上,同时你将常规的 git 存储库推送到远程机器.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆