从git中删除,但保留在工作目录中 [英] Remove from git but keep in working directory

查看:95
本文介绍了从git中删除,但保留在工作目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一堆由git跟踪的文件,但它们被错误地添加(并提交)。它们应该存在于工作目录中(它们是我的IDE使用的临时文件),但不能通过git进行跟踪。我现在已经创建了一个.gitignore文件并添加了相应的条目,但是将这些文件从git的跟踪中移除并将它们安全地放在我的工作目录中的正确方法是什么?




git rm --cached myfile / p>

完整说明: http://www.kernel.org/pub/software/scm/git/docs/git-rm.html



我也喜欢 - 干运行选项。它实际上并没有改变什么,只是显示哪些文件会受到真实命令的影响。最好先看看会发生什么,或者测试一下你的文件名模式。


I added a bunch of files to be tracked by git, but they were added (and committed) in error. They should be present in the working directory (they're ephemeral files used by my IDE), but not tracked by git. I've now created a .gitignore file and added the appropriate entries, but what is the proper way to remove the files from being tracked by git while leaving them safely in my working directory?

解决方案

Use the --cached option:

git rm --cached myfile

Complete explanation here: http://www.kernel.org/pub/software/scm/git/docs/git-rm.html

I also like the --dry-run option. It does not actually change anything, just show what files will be impacted by the real command. It's good to start with that to see what will happen, or to test your file name pattern.

这篇关于从git中删除,但保留在工作目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆