Git:如何排除存储库中的子文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4126732/
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
Git: how to exclude a subfolder in a repository?
提问by Mr Question
I have created a repository in a folder with my project, you know, git init
, I have the Webstorm folder .idea
and another one not related to this, I am not interested in keeping in the repository, and I don't want this folder to appear even as new files to add.
I want to forget about these subfolders.
我在我的项目的文件夹中创建了一个存储库,你知道,git init
我有 Webstorm 文件夹.idea
和另一个与此无关的文件夹,我对保留存储库不感兴趣,我什至不希望这个文件夹出现作为要添加的新文件。我想忘记这些子文件夹。
- How can I exclude this subfolder before committing the whole repository?
- How can I exclude this subfolder after committing the whole repository?
- 如何在提交整个存储库之前排除此子文件夹?
- 提交整个存储库后如何排除此子文件夹?
回答by wilhelmtell
Open the .git/info/exclude
file in a text editor and add the folder to ignore. This file remains private to you. You can also create a .gitignore
file in the repository's root directory, outside the .git
directory and write the folder entry there. Then add this file to the repository to share with others what content should be ignored, should others have this directory-to-ignore in their repository too.
.git/info/exclude
在文本编辑器中打开文件并添加要忽略的文件夹。此文件对您保密。您还可以.gitignore
在存储库的根目录中的目录外创建一个文件,.git
并将文件夹条目写入那里。然后将此文件添加到存储库以与其他人共享哪些内容应该被忽略,如果其他人在他们的存储库中也有这个要忽略的目录。
If you already committed this directory then just remove it with git rm -r --cached
, commit the deletion and mark the directory ignored as I described above. You might want to make a backup of the directory before you wipe it.
如果您已经提交了此目录,则只需使用 将其git rm -r --cached
删除,提交删除并将目录标记为忽略,如上所述。在擦除目录之前,您可能希望对其进行备份。