Git: how to exclude a subfolder in a repository?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 10:40:41

问题


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?

回答1:


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.



来源:https://stackoverflow.com/questions/4126732/git-how-to-exclude-a-subfolder-in-a-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!