git 如何从 Github 公共隐藏文件和文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33864292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide files and folders from Github public
提问by Michael Fulton
I just want to hide some of my git file from GitHub.
我只是想从 GitHub 中隐藏我的一些 git 文件。
Like this repo https://github.com/karlcoelho/undergrad.co
.
喜欢这个回购https://github.com/karlcoelho/undergrad.co
。
Is that possible using .gitignore
or any other way ?
可以使用.gitignore
或任何其他方式吗?
回答by Michael Fulton
Using the .gitignore file excludes files from being part of a push to any remotes such as Github, so if you clone the repo on another machine those files won't appear, and if you lose access to your machine the ignored files are gone for good because they are not part of the git version control.
使用 .gitignore 文件将文件排除在推送到任何远程(例如 Github)的一部分之外,因此如果您在另一台机器上克隆存储库,这些文件将不会出现,并且如果您无法访问您的机器,则被忽略的文件将消失很好,因为它们不是 git 版本控制的一部分。
Github offers premium Plans which all you to have private repositories. Marking a repository as private allows you to push and pull your repositories as normal and not have them in public view. Only you and any collaborators have access to the repository.
Github 提供高级计划,让您拥有私人存储库。将存储库标记为私有允许您像往常一样推送和拉取存储库,而不会将它们显示在公共视图中。只有您和任何协作者才能访问存储库。
Students with access to a .edu email address have access to the Github Student Developer Pack which gives you the Developer plan, granting unlimited private repositories and more: https://education.github.com/pack
可以访问 .edu 电子邮件地址的学生可以访问 Github 学生开发者包,该包为您提供开发者计划,授予无限的私人存储库等:https: //education.github.com/pack
Alternatively, you can use other git repository sites which allow free private repositories. Gitlab comes to mind.
或者,您可以使用其他允许免费私有存储库的 git 存储库站点。想到了 Gitlab。
回答by Brendan Molloy
You could simply not commit the files so they won't be pushed when you run git push
.
您可以简单地不提交文件,以便在您运行git push
.
Adding files to .gitignore
will stop you from accidentally adding those files to a commit.
将文件添加到.gitignore
将阻止您将这些文件意外添加到提交中。
回答by Ironheartbj18
After you created git add .gitignore
, I had a file name .env and put into the .gitignore.
I typed .env
. It does not work, so I had to change file of .env
to env
. It will not showing the public of env file.
创建后git add .gitignore
,我有一个文件名 .env 并放入.gitignore.
我输入的.env 文件中.env
。它不起作用,所以我不得不将文件更改.env
为env
. 它不会显示 env 文件的 public。
You can learn more hide-files-on-githublooking at their .gitignore file
您可以通过查看他们的 .gitignore 文件了解更多hide-files-on-github
- extension/node_modules/*
- !extension/node_modules/github-injection/index.js
- 扩展/节点模块/*
- !extension/node_modules/github-injection/index.js