You should establish a proper pattern for storing credentials instead. Many people use environment variables, but you can also use an external configuration file.
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.
"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."
I could see some uses for something like this. When I was working as a web programmer, I often had to do a lot if dev-server type things. Since at least one of the dev-server was often on my personal machine, it could often be a very different beast than the production server.
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.
In practice, I never use 'commit -a' or 'git add -A'. I prefer to use 'git gui' to interactively stage files or just specific lines. This way I can be sure of what is being committed.
Not as generic a solution as ignoring lines on commit (whatever they may contain or for whatever reason you want to hide them), but when it comes to protecting credentials, crypto for arbitrary chunks of text comes in handy.¹ The fact that the encrypted string is being committed still might be a good thing: as the code is run an error will be thrown as a reminder to either decrypt or replace the string with one’s own creds.
This is exactly what I was looking for few months back.
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.
Use the -p (--patch) flag, it works wonderfully for selectively marking blocks for staging (git add -p), and selectively checking out changed files with (git checkout -p).
My experience is that you'll quickly get burned if you do this for the use case the OP mentioned. The goal is to keep different settings for a development environment, not to just temporarily avoid committing. One day, you'll inevitably forget and accidentally commit and push the changes you've been carefully avoiding.
I think I would handle it by making a "template file", scrubbed from the secret sauce and a script that patches the template file into the real thing.
Only template file is checked into the repo.
You can put MySQL or MySQLi connection credentials in php.ini. Bu ignore line will be useful for me too, I have a second connection to the reports database.
[+] [-] oellegaard|11 years ago|reply
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
[+] [-] Mithaldu|11 years ago|reply
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:
However in development i want it to run like this: 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.
[+] [-] jpitz|11 years ago|reply
[+] [-] zak_mc_kracken|11 years ago|reply
[+] [-] peedy|11 years ago|reply
[+] [-] xorcist|11 years ago|reply
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.
[+] [-] InfiniteRand|11 years ago|reply
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.
[+] [-] _ikke_|11 years ago|reply
[+] [-] daigoba66|11 years ago|reply
[+] [-] oneeyedpigeon|11 years ago|reply
[1] https://mac.github.com/
[+] [-] pluma|11 years ago|reply
[+] [-] colinbartlett|11 years ago|reply
My teammates probably get tired of hearing it, but every time someone erroneously commits some file or line I advocate its use.
[+] [-] rhythmvs|11 years ago|reply
¹ https://packagecontrol.io/packages/Transcrypt
[+] [-] kivihiinlane|11 years ago|reply
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.
[+] [-] joaomsa|11 years ago|reply
[+] [-] michaelmior|11 years ago|reply
[+] [-] amelius|11 years ago|reply
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.
[+] [-] im3w1l|11 years ago|reply
[+] [-] darkhorn|11 years ago|reply
[+] [-] nivla|11 years ago|reply
[+] [-] manojlds|11 years ago|reply
Just .gitignore the .env file.