忽略 git 中已修改(但未提交)的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/655243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ignore modified (but not committed) files in git?
提问by csmosx
Can I tell git to ignore files that are modified (deleted) but should not be committed?
我可以告诉 git 忽略已修改(已删除)但不应提交的文件吗?
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).
情况是我在 repo 中有一个子目录,其中包含我根本不感兴趣的东西,所以我删除了它以防止它出现在自动完成等(在 IDE 中)。
But now, if I add that folder to .gitignore, simply nothing changes, all the stuff is shown as deleted by git status.
但是现在,如果我将该文件夹添加到 .gitignore,则不会发生任何变化,所有内容都显示为已被 git status 删除。
Is there a way to make git ignore it either way?
有没有办法让 git 忽略它?
(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?)
(或者,当我使用 git-svn 时,我可以将更改提交到本地 git 并确保它们不会传递到 svn 存储库吗?)
回答by csmosx
check out the git-update-index man pageand the --assume-unchanged bit and related.
查看git-update-index 手册页和 --assume-unchanged 位和相关的。
when I have your problem I do this
当我遇到你的问题时,我会这样做
git update-index --assume-unchanged dir-im-removing/
or a specific file
或特定文件
git update-index --assume-unchanged config/database.yml
回答by Dave L.
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.
一个更新更好的选择是
git update-index --skip-worktree
不会在硬重置或拉动的新更改中丢失。
See the man page at http://schacon.github.com/git/git-update-index.html
请参阅http://schacon.github.com/git/git-update-index.html 上的手册页
And a comparison at http://fallengamer.livejournal.com/93321.html
回答by Sujiraj R
Use this code
使用此代码
git update-index --assume-unchanged file-name
回答by John Feminella
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 with git rm --cached
.
跟踪的文件不能被忽略,因此您必须先将它们从索引中删除。添加一个.gitignore
忽略您不想要的目录,然后删除它们,并使用git rm --cached
.
回答by Walter
What I usually do is
我通常做的是
git stash
git whatever-else
git stash apply
git stash clear
混帐
git什么的
git stash 应用
git stash 清除