繁体   English   中英

忽略 git 中修改(但未提交)的文件?

[英]Ignore modified (but not committed) files in git?

我可以告诉 git 忽略已修改(删除)但不应提交的文件吗?

情况是我在 repo 中有一个子目录,其中包含我根本不感兴趣的东西,所以我删除了它以防止它出现在自动完成等(在 IDE 中)。

但是现在,如果我将该文件夹添加到 .gitignore,则根本没有任何变化,所有内容都显示为 git 状态已删除。

有没有办法让 git 忽略它?

(或者,当我使用 git-svn 时,我可以将更改提交到本地 git 并确保它们不会传递到 svn 存储库吗?)

查看git-update-index 手册页和 --assume-unchanged 位和相关的。

当我遇到你的问题时,我会这样做

git update-index --assume-unchanged dir-im-removing/

或特定文件

git update-index --assume-unchanged config/database.yml

更新更好的选择是git update-index --skip-worktree不会在硬重置或拉取的新更改时丢失。

请参阅http://schacon.github.com/git/git-update-index.html的手册页

并在http://fallengamer.livejournal.com/93321.html进行比较

使用此代码

git update-index --assume-unchanged file-name

我通常做的是

git stash

git whatever-else

git stash apply

git stash clear

跟踪的文件不能被忽略,因此您必须先将它们从索引中删除。 添加一个.gitignore忽略您不想要的目录,然后删除它们,并使用git rm --cached删除任何落后者。

在我的情况下有效:

git restore --staged filename

示例: git restore --staged index.js

暂无
暂无

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

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