忽略 git 中修改(但未提交)的文件?
我可以告诉 git 忽略已修改(删除)但不应提交的文件吗?
情况是我在存储库中有一个子目录,其中包含我根本不感兴趣的内容,因此我将其删除以防止它出现在自动完成等内容中(在 IDE 中)。
但现在,如果我将该文件夹添加到 .gitignore,则不会发生任何变化,所有内容都显示为已被 git status 删除。
有没有办法让 git 忽略它?
(或者,当我使用 git-svn 时,我可以将更改提交到本地 git 并确保它们不会传递到 svn 存储库吗?)
Can I tell git to ignore files that are modified (deleted) but should not be committed?
The situation is that I have a subdirectory in the repo which contains stuff I'm not interested in at all, so I deleted it to prevent it showing up in auto-completions and the like (in the IDE).
But now, if I add that folder to .gitignore, simply nothing changes, all the stuff is shown as deleted by git status.
Is there a way to make git ignore it either way?
(Alternatively, as I'm using git-svn, could I commit the changes to the local git and ensure they are not passed on to the svn repo?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
查看 git-update-index 手册页 和 --assume - 不变位和相关。
当我遇到你的问题时,我会执行此操作
或特定文件
check out the git-update-index man page and the --assume-unchanged bit and related.
when I have your problem I do this
or a specific file
更新更好的选择是
git update-index --skip-worktree 不会因硬重置或拉取的新更改而丢失。
请参阅手册页。
比较 http://fallengamer.livejournal.com/93321.html
A newer and better option is
git update-index --skip-worktree
which won't be lost on a hard reset or a new change from a pull.See the man page.
And a comparison at http://fallengamer.livejournal.com/93321.html
使用此代码
Use this code
跟踪的文件不能被忽略,因此您必须首先将它们从索引中删除。 添加一个
.gitignore
来忽略您不需要的目录,然后删除它们,并使用git rm --cached
删除所有落后者。Tracked files can't be ignored, so you'll have to remove them from your index first. Add a
.gitignore
that ignores the directories you don't want, then delete them, and remove any stragglers withgit rm --cached
.我通常做的是
What I usually do is
在我的案例中有效的方法:
git restore --staged filename
示例:
git restore --staged index.js
What worked in my case:
git restore --staged filename
Example:
git restore --staged index.js