简体   繁体   中英

How can I untrack files in Git according to my .gitignore file?

I have tracked many many files early, but I don't want Git to track them any more from now on.

Can I untrack those files according to a .gitignore file?

There are too many files and they are separated in many different directories, so it is not practical to remove them one-by-one, instead, I hope they can be untracked according to patterns in a .gitignore file.

You need to remove the files from the index.

git rm -r --cached . 

and then add

git add .

Finally commit:

git commit -a -m "Untrack ignored files!"

You can stop tracking already-tracked files by staging a deletion of the file in the index:

git rm --cached path/to/ignored/file

... and committing.

With --cached this won't actually delete the file in your working copy. (I'm always paranoid and copy them somewhere safe first, anyway.)

您可以使用以下命令获取所有被忽略文件的列表:

 git ls-files --others -i --exclude-standard

使用git rm删除您不再希望跟踪的文件,然后将这些文件添加到.gitignore ,它们将不再出现在您的未暂存更改列表中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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