为什么即使我输入文件名后 gitignore 也无法工作?

Why is gitignore not working even after i put the file name in?

我有一个名为 sohuku.txt 的文件。我有另一个名为 .gitignore.txt 的文件夹,我在其中放置了 'sohuku.txt',但是当我在 PowerShell 中键入 'git add .' 然后键入 git 状态时,它显示文件更改为做出承诺。怎么办?

.gitignore 文件应位于存储库的根目录并正确命名。 https://git-scm.com/docs/gitignore

文件必须命名为 .gitignore,而不是 .gitignore.txt

如果 windows 不允许您重命名它(如“您必须输入文件名”之类的错误),则将其重命名为 .gitignore.

gitignore 是文件,从文件名中删除 .txt

.gitignore.txt -> .gitignore

不要将 .txt 放在 .gitignore 文件中...

所以你可以将不想推送的文件名传给git。

在根 / 目录中创建 .gitignore 文件,不带任何扩展名。

/
  src
     index.js
  .gitignore

要删除 .txt 文件,只需在 .gitignore 文件中添加

*.txt

并删除旧的提交:

$ git reset HEAD~                                          
<< edit files as necessary >>                              
$ git add ...                                              
$ git commit -c ORIG_HEAD

Undo git to learn more