将先前忽略的目录添加到 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23296370/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:59:11  来源:igfitidea点击:

Add previously ignored directory to Git repository

linuxgit

提问by user1032531

My .gitignorefile looks like:

我的.gitignore文件看起来像:

html/
cache/
resources/
# Temp files often created by editors
*.~

I know wish to start tracking a specific directory in html, so I add `!html/support/

我知道希望开始跟踪 html 中的特定目录,所以我添加了 `!html/support/

html/
cache/
resources/
# Temp files often created by editors
*.~
# Track support
!html/support/

After doing so, however, Git still doesn't seem to track html/support/ and all its children.

然而,这样做之后,Git 似乎仍然没有跟踪 html/support/ 及其所有子项。

How do I add a previously ignored directory to Git repository?

如何将以前忽略的目录添加到 Git 存储库?

回答by blue112

Not ignoring doesn't mean tracking.

不忽视并不意味着跟踪。

Just use

只需使用

git add html/support/

at the root of your git repository.

在 git 存储库的根目录。

If the file is still ignored, though, you can use git add -fto force adding it (this will not modify the .gitignorefile, just allow one little exception) :

但是,如果文件仍然被忽略,您可以使用git add -f强制添加它(这不会修改.gitignore文件,只允许一个小例外):

git add -f html/support/

回答by greencheese

You can simply go to the Directory of the File where .gitignorefile is located. This File contains all the files that are ignored. You can simply remove the file listing and save it. Then Refresh your project. Then you will be able to commit those files.

您可以简单地转到.gitignore文件所在的文件目录。此文件包含所有被忽略的文件。您可以简单地删除文件列表并保存它。然后刷新您的项目。然后您将能够提交这些文件。