使用 .git/info/exclude 太晚了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1158857/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:45:55  来源:igfitidea点击:

working with .git/info/exclude too late

gitgitignore

提问by Dan Rosenstark

I usually do this:

我通常这样做:

git init
git add .
git commit .

And then I realize that it's about to add my nbproject directory, which I want excluded/ignored. Sometimes, I even check in this directory. Had I added it to .git/info/exclude before running git add., everything works fine (it's excluded).

然后我意识到它即将添加我的 nbproject 目录,我想排除/忽略它。有时,我什至检查这个目录。如果我在运行 git add. 之前将它添加到 .git/info/exclude,一切正常(它被排除在外)。

So then I modify .git/info/exclude and then it's too late. git no longer respects changes to .git/info/exclude.

然后我修改 .git/info/exclude ,然后为时已晚。git 不再尊重对 .git/info/exclude 的更改。

So the questions are:

所以问题是:

  1. How can I get git to take up the changes in the exclude file in the checkin?(I tried running git add . again, which doesn't help)
  2. Let's say I check in a directory (or file) that I want excluded. What is the least number of steps to get to the state I want(with the file excluded).
  1. 我怎样才能让 git 在签入中接受排除文件中的更改?(我再次尝试运行 git add . ,这没有帮助)
  2. 假设我签入了要排除的目录(或文件)。达到我想要的状态的最少步骤是多少(排除文件)。

回答by Greg Hewgill

To remove a file that you have added but not committed, use a command like this:

要删除已添加但未提交的文件,请使用如下命令:

git rm --cached file.to.remove

This will remove the file from the index, but not touch the file on disk.

这将从索引中删除文件,但不会触及磁盘上的文件。

To remove a file (or files) from the most recentcommit, use the above git rm --cachedcommand followed by git commit --amend.

要从最近的提交中删除一个(或多个)文件,请使用上面的git rm --cached命令,后跟git commit --amend.