Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force git to ignore a directory and all present and future files within

So, I'm a newbie at git, but I'm using it because I have my rails app deployed through heroku. My app generates a bookmarklet (which is just a js file) for each user upon sign-up. Unfortunately, when I deploy, all of the bookmarklets for the users on the live site get overwritten with the bookmarklets for the users on my dev environment. I've read some other questions about this kind of thing, and I know I'll have to add the bookmarklet folder to the .gitignore file, and something about rm --cache (but I'm not sure exactly what I'll have to do). I tried doing these things, but I'm wondering if the problem is that git is ignoring all of the files that are there now, but isn't ignoring the ones that are generated after doing the whole gitignore process. Either that or I'm just doing it wrong (this is very, very likely).

Any help is welcome. And sorry that this covers the same ground as a lot of other similar questions. I did as much research as I could.

Thanks.

like image 291
Bon Champion Avatar asked Mar 31 '12 21:03

Bon Champion


People also ask

How do I set Git to ignore files?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Can I Git locally ignore?

A local . gitignore file is usually placed in the root directory of a project. You can also create a global . gitignore file and any entries in that file will be ignored in all of your Git repositories.


2 Answers

Here some simple steps:

  1. Create a file .gitignore in the root of your repository, with the following simple content:

    /path/to_your/folder
    
  2. Add the file to your repository:

    git add .gitignore
    
  3. Remove the folder from your repository (this won’t physically delete the folder):

    git rm --cached /path/to_your/folder
    
  4. Commit

    git commit
    

After that, the folder should be removed from your repository and subsequent changes in it will be ignored by git.

like image 134
poke Avatar answered Oct 25 '22 11:10

poke


Sounds like Heroku is cleaning out every file not checked in to your Git repository when you deploy. Modify your app to save the bookmarklets to a directory outside of your Git repository.

like image 32
Richard Hansen Avatar answered Oct 25 '22 12:10

Richard Hansen