Live data from Hacker News

Git: ignore file lines

benmezger.me

1–10 of 40 posts

Re: Git: ignore file lines

#2
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

Re: Git: ignore file lines

#3

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

If you read what TFA says:

    "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."

Re: Git: ignore file lines

#4
post #3

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

If you read what TFA says: "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'd still argue that this is an anti-pattern. If you find yourself in a situation where you want to leave out a line from git in the middle of a file, you should reconsider the structure of your code/project/whatever.

Re: Git: ignore file lines

#5
post #3

Earlier quoted context omitted.

If you read what TFA says: "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'd still argue that this is an anti-pattern. If you find yourself in a situation where you want to leave out a line from git in the middle of a file, you should reconsider the structure of your code/project/whatever.

Agreed. The article isn't particularly useful because it essentially says "this is how you solve a 'problem' that I'm only going to demonstrate by giving an example I immediately dismiss" and not explaining the type of situation in which this might be useful. Every time I've found myself in a similar situation, the problem has not been that git doesn't allow me to pretend that certain lines in a file don't exist, it's been that my design has been lacking.

Re: Git: ignore file lines

#6
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.

Re: Git: ignore file lines

#7

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.

Github's app [1] does much the same thing, but (IMO) with a much nicer interface. And it works with any git repo, not just one with a github remote.

[1] https://mac.github.com/

Re: Git: ignore file lines

#9

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

If you're on a django project, most probably you're using virtualenv. I had a habit of just putting environment variables in the postactivate script.

Re: Git: ignore file lines

#10

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

Ok, here, have a better example:

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.

Post reply on HN