如何将 .gitignore 文件夹中的文件添加回项目

How to add files from .gitnore folder back into project

我有几个文件隐藏在 Intellij 2017 中。隐藏文件似乎在 .gitignore 文件夹中。我需要那些文件。所以我想知道如何将这些文件添加回我的项目,并从 .gitignore 文件夹中删除。我看到的唯一搜索结果是如何删除一个文件,它将完全从我的项目中删除文件。

一个"clean explicit solution"我喜欢用的是:

1st 创建一个提交,从 .gitignore 文件中删除(或注释掉)忽略的路径。

第二,创建一个提交以添加工作树中现在未被忽略的所有文件。

当然,这是从一个站点执行,该站点实际上 具有 您要添加到 git 源代码管理中的文件。


引用自git document

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

示例:

$ cat .gitignore
vmlinux*
$ ls arch/foo/kernel/vm*
arch/foo/kernel/vmlinux.lds.S
$ echo '!/vmlinux*' >arch/foo/kernel/.gitignore