Another simple pattern used a lot in django:
try: from local_settings import * except Exception: pass
Then put any variable you want to override in local_settings.py and put local_settings.py in .gitignore
I contract for a company which has set rules for their stuff. Trying to change these rules would be an amount of effort similar to becoming CEO, starting out as a deckswabber.
One of their project is a web app. It has an .htaccess file. In production it is configured to run like this:
Addhandler fcgid-script .fcgi
However in development i want it to run like this: Addhandler cgi-script .fcgi
Normally you'd just put the entire file on ignore with --assume-unchanged, but that doesn't work well, since the file also contains other bits of configuration that are important for the app, and get changed fairly frequently.OP's tool is perfect for this kind of situation.
Projects sometimes check in an IDE formatting file settings to ensure that all developers use the same formatting. There are a couple of times where I wanted to add my own little formatting detail (which didn't conflict with the project's) but couldn't because doing so would mark that file modified and force me to remember to undo my changes before each push.
With the hack from the article, I have now a working solution out of this.
.htaccess is ignored while the .htaccess.dist template is part of the reop
Note that --assume-unchanged means you are promissing to git that the file hasn't changed, so it doesn't have to lookt at it every time you invoke git status (for performance reasons).
When you break that promise, git will complain, just like you said.
That's not even remotely possible.
"Of course this is a stupid example, you would probably
put the username, password and other important stuff in
another file, say a config file, but let’s assume that
this is not possible, or somehow this variable cannot be
else where."Do you expect to develop on your production systems?
Do you also store databases in the same directory?
I can not think of a possible use case for this, but I guess there must be since this at least someone seems to recognize it.
My teammates probably get tired of hearing it, but every time someone erroneously commits some file or line I advocate its use.
I guess what this really is a matter of is configuration management, for certain configurations you will have certain lines of code that will not matter or that will confuse. While you can manage this within your code in various ways (such as the #ifdef _DEBUG macro, etc.), it would be natural for the VC to handle this.
For a general features, maybe you could either specify in a configuration file, particular lines of a file or a regular expression to designate lines to ignore or better yet to only apply to certain branch checkouts.
A nice feature to think about for my "one-of-these-days-I-will-make-a-beter-version-control-system" file.
I was working on a rather large and very messy project back then. Project used popular framework with very specific config files but previous dev choose to ignore them most of the time so configurations were all over the place. I didn't have much time to start looking more deeply into the git so I just ended up using 'local-config' branch that had my environment specific configs that I always rebased on top of master and deleted on commit. Wasn't perfect solution but it worked.
I know it can be done (tried it about a year ago), but it was too much of a hassle to use it on all of my repositories.
Just .gitignore the .env file.