2

I have a folder in my local repo called var, which sits in the root directory. As with most var folders, it's full of junk, several of which files are too large for Git to push.

I've included the following in my .gitignore in several attempts:

var   
var/  
var/log/  
var/log  
var/

I ran:

git rm -r --cached .   
git update-index   
git update-index --assumed-unchanged

in various combinations with no joy! Any suggestions?

svick
  • 236,525
  • 50
  • 385
  • 514
Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68

1 Answers1

5

All entries in .gitignore prevent git from listing untracked files when you type git status. That doesn't mean you can't add or commit them. In fact, you can.

Tracked files will stay tracked even if they get added into .gitignore. So, in order to make them disappear from your repository, you will need to untrack them.

To do that, you need to delete them (or at least make git think so):

git rm -r --cached var

If you type git status you will see that git now thinks you have deleted all the files in var. Commit that. After that, git status will tell you that you have a bunch of untracked files in var. That is, because the files weren't actually deleted, you only made git think so. Now add the folder to your .gitignore and they should be ignored.

functionpointer
  • 1,411
  • 1
  • 13
  • 18
  • 1
    I've tried **git rm -r --cached var** and it pushes it anyway for some reason, if I run that command it says "fatal: pathspec 'var' did not match any files" so am I right in guessing that already means it's being untracked? When I then do git add . and push the files, it then throws the same error about files in var. Thanks for your response! – Ewan Valentine Sep 13 '13 at 11:15
  • Well, you need to make `var` a valid path. If the folder is located in some subfolder, you will need to change the path, or `cd` into that subfolder first. The same is valid in reverse direction, if you are in some subfolder, you may need to `cd ..` out there first. – functionpointer Sep 13 '13 at 11:22