Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git still adds and tracks folders marked in .gitignore [duplicate]

Tags:

git

gitignore

I have a few folders in Git added in my ".gitignore" file. They contain over 100k files. Mainly images, tmp and cache stuff. What I need is to be able to commit changes to my code with out committing what happens in those folders.

I thought adding them into the ".gitignore" would do the trick but for some reason it's not working at all. I haven't been able to commit anything to the repo in days because every time I try the push command it tries sending 100k files then it freezes and times out.

root@serveur [/home/***/***]# git push origin master Password: Counting objects: 110300, done. 

How can I force Git to reindex the tree while taking in consideration the ignored folders so I can finally commit all the changes I made to the code?

like image 634
Patrick Simard Avatar asked Aug 24 '13 12:08

Patrick Simard


People also ask

Why are file added in Gitignore still tracked?

“file added to gitignore still tracked” Code Answer's gitignore file – for instance, add a folder you don't want to track to . gitignore . git rm -r --cached . – Remove all tracked files, including wanted and unwanted.

How do you remove files that are listed in the .gitignore but still on the repository?

As the files in . gitignore are not being tracked, you can use the git clean command to recursively remove files that are not under version control. Use git clean -xdn to perform a dry run and see what will be removed. Then use git clean -xdf to execute it.

How do I stop a git track from being tracked?

Using git rm to Stop Tracking Files in Git We can remove the file from tracking in Git by using the git rm command with the --cached option. We can also remove a folder from tracking in the Git repository using the following command.


1 Answers

The reason it isn't working is (probably) because you added some of those files before you added the .gitignore - so you have to remove them from git before they're able to be ignored.

Source: https://stackoverflow.com/a/1139797/2128691

First, commit any outstanding code changes, and then, run this command:

git rm -r --cached . 

This removes everything from the index, then just run:

git add . 

Commit it:

git commit -m ".gitignore is now working" 
like image 128
dax Avatar answered Sep 30 '22 22:09

dax