简体   繁体   English

git 忽略更改但不删除文件

[英]git ignore changes but do not delete files

Essentially I made a mistake to not include 2 directories in .gitignore before I had to make some analysis.本质上,在我不得不进行一些分析之前,我犯了一个错误,即在.gitignore中不包含 2 个目录。 The result is that these analysis have produced an overwhelming amount of files and now I have 5000 tracked changes on my git repository.结果是这些分析产生了大量的文件,现在我的 git 存储库上有 5000 个跟踪更改。 I would like to ignore those changes and make git look at my updated .gitignore , but I don't want to remove any of the files produced by my analysis.我想忽略这些更改并让 git 查看我更新的.gitignore ,但我不想删除我的分析产生的任何文件。 What is the appropriate git command for that please.请问什么是合适的git命令。

Is it git reset --hard [HEAD] ?git reset --hard [HEAD]吗? I don't want to make any silly mistakes.我不想犯任何愚蠢的错误。

just remove all git cache:只需删除所有 git 缓存:

git rm -r --cached .

When all files are removed from the index, you can add the regular files back (the one you did not want to ignore)从索引中删除所有文件后,您可以重新添加常规文件(您不想忽略的文件)

$ git add .
$ git commit -am 'Removed files from the index (now ignored)'
$ git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM