简体   繁体   English

停止跟踪并忽略文件,就像从未在Git中添加文件一样

[英]Stop tracking and ignore file as if it were never added in Git

I've accidentally committed some files that shouldn't be tracked and should be generated for each developer on their own. 我不小心提交了一些不应该跟踪的文件,应该由每个开发人员自行生成。 I've added a pattern to .gitignore for them, but that's too late of course because the files are already in the repo. 我为他们在.gitignore中添加了一个模式,但这当然为时已晚,因为文件已经在存储库中。 I've checked the answers to these questions, but they all say the same thing: 我检查了这些问题的答案,但它们都说相同的话:


The command: 命令:

git rm --cached <file>

doesn't work because if I commit that, then the other developers will have their versions of the file deleted once they pull. 不起作用,因为如果我这样做,那么其他开发人员将在拉出后删除其文件版本。

git update-index --assume-unchanged <file>

..doesn't work either because the files are still being tracked, so if anyone makes changes, they will be committed unless each developer runs the command. ..也不起作用,因为仍在跟踪文件,因此,如果任何人进行更改,除非每个开发人员都运行命令,否则它们将被提交。 Either way, it keeps the files in the repository, which we don't want. 无论哪种方式,它都将文件保留在我们不想要的存储库中。

Is there a way to make it as if the files were never in the repository in the first place? 有没有办法让它们看起来像文件从未存储在仓库中? I want the same behavior as git rm --cached <file> without the caveat of it causing the files to be deleted on a pull.. 我想要的行为与git rm --cached <file>相同, git rm --cached <file>没有警告,导致文件一经删除就被删除。

"Is there a way to make it as if the files were never in the repository in the first place?" “是否有一种方法可以使文件从一开始就不在存储库中?” "I wouldn't personally use [a rebase] since it's the same problem of requiring all the other developers to take some action" “我个人不会使用[rebase],因为这是要求所有其他开发人员采取某些措施的同一个问题”

Then there is no solution. 那就没有解决办法了。 That's the nature of git, committed and pushed mistakes are forever. 这就是git的本质,犯错和推入错误是永远的。 This is a feature, not a bug. 这是一个功能,而不是错误。

This is a pretty common scenario and the answer might be helpful to others 这是一个很常见的情况,答案可能对其他人有帮助

Reading the documentation would be better. 阅读文档会更好。

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

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