使用.git / info /排除太晚 [英] working with .git/info/exclude too late

查看:302
本文介绍了使用.git / info /排除太晚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常这样做:

  git init 
git add。
git commit。

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

然后我修改.git / info / exclude,然后就太晚了。 git不再尊重.git / info / exclude的变更。



所以问题是:


  1. 如何让git在签入时接受排除文件中的更改?(我试着再次运行git add,这没有帮助)

  2. 假设我检入了我想要排除的目录(或文件)。到达我想要的状态的步骤数量最少是多少(排除文件)。


解决方案

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

  git rm --cached file.to.remove 

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



删除文件(或文件),使用上面的 git rm --cached 命令,然后使用 git commit - -amend


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).

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).

解决方案

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.

这篇关于使用.git / info /排除太晚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆