我如何使用文件“.git/info/exclude” 为时已晚?

发布于 2024-07-27 15:14:11 字数 509 浏览 3 评论 0原文

我通常这样做:

git init
git add .
git commit .

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

然后我修改了.git/info/exclude,然后就太晚了。 Git 不再考虑对 .git/info/exclude 的更改。

所以问题是:

  1. 如何让 Git 在签入时接受排除文件中的更改? (我尝试再次运行 git add . ,但这没有帮助)
  2. 假设我签入了要排除的目录(或文件)。 达到我想要的状态最少需要多少步? (排除该文件)。

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 would have worked fine (it's excluded).

So then I modify .git/info/exclude and then it's too late. Git no longer respects changes to .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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦慕雪 2024-08-03 15:14:11

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

git rm --cached file.to.remove

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

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

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 recent commit, use the above git rm --cached command followed by git commit --amend.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文