4

I have added vendor folder to my .gitignore file, but still whenever I do git status it shows me that vendor folder is modified. Below are my steps that I followed in order to push my code to my repository:

  1. Created .gitignore file with following content:

    .idea/*
    log/*
    tmp/*
    
  2. Pushed .gitignore file to repository:

    git add .
    git commit -m "test"
    git push origin master
    
  3. Created new project that contains vendor folder

  4. Pushed project with vendor folder to repository:

    git add .
    git commit -m "test"
    git push origin master
    
  5. Modified .gitignore file to ignore vendor folder:

    .idea/*
    log/*
    tmp/*
    vendor/bundle/*
    vendor/cache/*
    vendor/plugins/*
    

But wherever I do git status it shows:

modified:   vendor/bundle/ruby/1.9.1/bundler/gems/jquery-rails-f79e8f178

even if the vendor folder is in .gitignore file.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
user2588480
  • 107
  • 2
  • 10
  • 1
    possible duplicate of http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-gitignored – Nitin Jain Dec 20 '13 at 12:11

2 Answers2

10

.gitignore only causes new, untracked files to be ignored. If a file was already added to the repository, like files in the vendor directory in this case, they will still be tracked.

You will have to remove the vendor files from the repository as well as adding them to .gitignore. This can be accomplished with git rm --cached <file>, which will remove <file> from the repository, but will not delete it from your working copy.

The next time you push to your remote, the files that you removed this way will be deleted from the remote.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • I am using ruby on rails as a backend.Vendor folder contains javascript and stylesheet folder in which jquery plugin and css frameworks are kept.so i cant ignore whole vendor folder.i want to ignrore all folders inside vendor except vendors/assets/javascripts and vendor/assets/stylesheet – user2588480 Dec 20 '13 at 14:02
  • Hey chris - I found the solution "git update-index --assume-unchanged " , but it is file specific. what if i want to do the same for directory.?? – user2588480 Dec 20 '13 at 14:30
  • You can use shell globbing: `git update-index --assume-unchanged dir/*`, assuming you're on Linux with Bash or something similar. I don't believe this will work with `cmd.exe` on Windows, since globbing there is performed by the command, not the shell. For deeper nesting you should be able to use `find`, e.g. `find dir/ -type f -exec git update-index --assume-unchanged {} +;`. This also assumes Linux or similar. I like to echo this command out before running it by putting `echo` between `-exec` and `git`, just to see what it will do. Safety first! – ChrisGPT was on strike Dec 20 '13 at 18:08
  • '[Assume-unchanged should not be abused for an ignore mechanism. It is "I know my filesystem operations are slow. I'll promise Git that I won't change these paths by making them with that bit… Especially, it is *not* a promise by Git that Git will always consider these paths are unmodified—if Git can determine a path that is marked as assume-unchanged has changed without incurring extra lstat(2) cost, it reserves the right to report that the path *has been* modified (…`git commit -a` is free to commit that change).](https://public-inbox.org/git/xmqqy4z5go1y.fsf@gitster.dls.corp.google.com/)' – ChrisGPT was on strike Jun 09 '22 at 15:00
-2

You are adding vendor directory wrong way. Try with below one.

/log/*.log
/tmp
/vendor
Pravin Mishra
  • 8,298
  • 4
  • 36
  • 49
  • :- actually vendor folder contains four folder namely assets,bundles , cache and plugin.I dont want assets folder to be ignore by git and thats why i am doing Vendor /bundle/* , vendor/cache/* and vendor/plugin/*.pls let me know if there is another way to write this. – user2588480 Dec 20 '13 at 12:40
  • Have a look http://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder – Pravin Mishra Dec 20 '13 at 12:47