Git:如何排除存储库中的子文件夹? [英] Git: how to exclude a subfolder in a repository?

查看:146
本文介绍了Git:如何排除存储库中的子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的项目在一个文件夹中创建了一个仓库,您知道, git init ,我有Webstorm文件夹 .idea 和另一个与此无关,我不想保存在存储库中,我不希望此文件夹即使作为新文件添加。
我想忘记这些子文件夹。


  1. 在提交整个存储库之前,如何排除此子文件夹?

  2. 如何在提交整个资料库后排除此子文件夹? p>在文本编辑器中打开 .git / info / exclude 文件并添加要忽略的文件夹。这个文件对你来说是保密的。您还可以在 .git 目录之外的存储库根目录中创建 .gitignore 文件并写入文件夹条目那里。然后将此文件添加到存储库,以便与其他人共享哪些内容应该被忽略,如果其他人在其存储库中也有该目录要忽略。



    如果您已经提交这个目录然后用 git rm -r --cached 删除它,提交删除并标记被忽略的目录,如上所述。在擦除之前,您可能需要对目录进行备份。


    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.

    1. How can I exclude this subfolder before committing the whole repository?
    2. How can I exclude this subfolder after committing the whole repository?

    解决方案

    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.

    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:如何排除存储库中的子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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