有没有办法只将GitHub中的特定文件公开?

huangapple go评论92阅读模式
英文:

Is there a way to make only certain files in github public?

问题

有没有办法使GitHub存储库中的某些文件公开,同时保持其他文件私有?

英文:

I have several sensitive images on a computer vision program I created that I don't want public but I want to share the main python code. Is there a way to make only certain files in a github repository public while keeping other files private?

答案1

得分: 1

# 将敏感文件添加到您的`.gitignore`文件中,以防止它们被Git检测到:
# 添加特定文件:
path/to/sensitive/file.txt
# 添加整个文件夹:
a/whole/folder
# 添加所有类型为“txt”的文件
*.txt

您可以在这里找到.gitignore的文档:https://git-scm.com/docs/gitignore

请注意,这不会使Git“忘记”已经被跟踪的文件,要取消跟踪文件而不从计算机中删除它们,您需要使用git rm --cached file_to_untrack.txt。省略--cached以从计算机中删除文件。

英文:

Add sensitive files to your .gitignore file, which will prevent them from being picked up by Git:

# Add a specific file:
path/to/sensitive/file.txt
# Add an entire folder
a/whole/folder
# Add all files of type "txt"
*.txt

You can find documentation for .gitignore here: https://git-scm.com/docs/gitignore

Note that this will not make git "forget" already tracked files, to untrack files without deleting them from your computer, you'll have to git rm --cached file_to_untrack.txt. Omit --cached to delete from your computer as well.

答案2

得分: 1

你可以使用git-crypt来实现这个目标:

git-crypt允许你自由共享一个包含公开和私有内容混合的存储库。git-crypt会优雅地降级,所以没有秘密密钥的开发者仍然可以克隆和提交带有加密文件的存储库。这使你可以将秘密材料(如密钥或密码)存储在与你的代码相同的存储库中,而无需锁定整个存储库。

https://github.com/AGWA/git-crypt

这允许你将文件检入并与合作者共享(或不共享)。

英文:

You could use git-crypt for this:

>git-crypt lets you freely share a repository containing a mix of public and private content. git-crypt gracefully degrades, so developers without the secret key can still clone and commit to a repository with encrypted files. This lets you store your secret material (such as keys or passwords) in the same repository as your code, without requiring you to lock down your entire repository.

https://github.com/AGWA/git-crypt

This lets you check the files in and share them (or not) with collaborators.

huangapple
  • 本文由 发表于 2023年7月28日 04:13:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76783118.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定