由于某种原因,我的.gitignore文件无法正常工作,而且没有多少谷歌搜索能够修复它

*.apk
*.ap_
*.dex
*.class
**/bin/
**/gen/
.gradle/
build/
local.properties
**/proguard/
*.log

它在主目录中,这是我的git repo。我运行Git 1.8.4.2,因为我使用的是运行OSX 10.8.6的MacBook。


当前回答

stackoverflow上有很多答案,但对我有用的并不是任何一个特定的答案,我在这里以简单的方式逐一记下所有需要完成的步骤:

预---备份回购以备不时之需。(我没有,但可能会让你觉得更安全)

确保这是您的第一次提交还是更早提交这些文件已添加,因此已被缓存。如果是,则git rm-r--缓存。和gitadd。(不要错过点)如果仍然无法工作,请在记事本中打开文件

转到文件->另存为将编码更改为ANSI。(有些答案错误地说UTF-8,但它不起作用,不必要地浪费时间)

Again git rm -r --cached .
    and git add . (do not miss the dot) 

Now do Git status and verify
    what we wanted has happened

其他回答

就我而言

我使用gitbash编写了以下命令:

echo[Enter_your_file_name.extension]>>.git忽略

然后执行推入式回购,并且工作正常

在cmd窗口中,使用下面的git命令,

git rm—缓存的文件名

解释:

gitrm-从工作树和索引中删除文件

--高速缓存的使用此选项可以取消分级并仅从索引中删除路径。工作树文件,无论是否修改,都将被单独保留。

--来自https://git-scm.com/docs/git-rm

我已经完成了echo-node_modules>>.gitignore,但没有成功。

出于某种原因,vscode的终端将文件保存在UCS-2LE BOM中,git似乎不接受这一点。

我使用记事本打开文件并将其转换为UTF-8++

它现在起作用了。

我认为他们需要解决这个问题,因为echo“filetoignore”>>

我通过以下方式解决了问题:

首先,我是一个windows用户,但我也遇到过类似的问题。所以,我在这里发布我的解决方案。

有一个简单的原因,为什么有时.gitignore不能像预期的那样工作。这是由于EOL转换行为。

这里有一个快速解决方案

编辑>EOL转换>Windows格式>保存

您可以将此归咎于文本编辑器设置。

例如:

由于我是一名windows开发人员,我通常使用Notepad++编辑文本,而不是Vim用户。

因此,当我使用Notepad++打开.gitignore文件时,会出现如下情况:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore


# See https://help.github.com/ignore-files/ for more about ignoring files.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.dll
*.force
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

如果我使用默认记事本打开同一个文件,这就是我得到的

## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## ## Get latest from  https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # See https://help.github.com/ignore-files/ for more about ignoring files. # User-specific files *.suo *.user *.userosscache 

因此,通过查看输出,您可能已经猜到了。gitignore中的所有内容都变成了一行,因为开头有一个##,所以它就好像所有内容都被注释了一样。

解决此问题的方法很简单:只需使用Notepad++打开.gitignore文件,然后执行以下操作

编辑>EOL转换>Windows格式>保存

下次使用windows默认记事本打开同一文件时,所有内容都应正确格式化。试试看这是否适合你。

stackoverflow上有很多答案,但对我有用的并不是任何一个特定的答案,我在这里以简单的方式逐一记下所有需要完成的步骤:

预---备份回购以备不时之需。(我没有,但可能会让你觉得更安全)

确保这是您的第一次提交还是更早提交这些文件已添加,因此已被缓存。如果是,则git rm-r--缓存。和gitadd。(不要错过点)如果仍然无法工作,请在记事本中打开文件

转到文件->另存为将编码更改为ANSI。(有些答案错误地说UTF-8,但它不起作用,不必要地浪费时间)

Again git rm -r --cached .
    and git add . (do not miss the dot) 

Now do Git status and verify
    what we wanted has happened