简体   繁体   中英

Git prevent checkout for ignored directories

I work on a project in a team and I need to checkout branches of others from time to time. Here is the thing.

All CSS and JS files are compiled from SASS/Coffeescript and it's all stored in /Static directory. Obviously the compiled files are not included in remote repository. So I clone repository and compile them so I can run it on my local machine. I put the /Static directory into .gitignore .

Now let's say I run a checkout to a different branch. Everytime I do that, it aborts because there are uncommited files (those compiled ones). If I run git checkout <branch> --force they obviously dissapear, so I have to compile them everytime I run a checkout.

So, how can I make git completely ignore /Static directory (or any other I'd possibly want to) when commiting, checkout or any other operation? In other words: How can I make directories inside repository completely inactive in terms of git operations? Thanx

You should add /Static to .git/info/exclude in your repository. It acts as a repository-wide mechanism for ignoring files.

I think you're not really ignoring /Static. If /Static was really ignored, you could be able to do what you want without problems.

What I think is that you have added /Static to .gitignore, but /Static was previously being control-versioned, so the inclusion in .gitignore has no effect.

I mean, if the initial clone contained /Static, that means /Static was being control-versioned. To start ignoring something that was previously versioned, you have first to stop control-versioning it:

git rm --cached <your-directory>

and then to start ignoring it

<add your directory to .gitignore>
git commit -m "Removed <directory> from control version."

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