Live data from Hacker News

Git: ignore file lines

benmezger.me

21–30 of 40 posts

Re: Git: ignore file lines

#21

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-scrip…

What happens if someone accidentaly committed the Addhandler cgi-script .fcgi change?

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.

Re: Git: ignore file lines

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

Re: Git: ignore file lines

#23

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…

Why not just keep environment dependent settings in a separate file that is not tracked? Then you have no problem with files that are 'half-tracked'.

Re: Git: ignore file lines

#24
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).

Re: Git: ignore file lines

#25

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-scrip…

Actually this is a good example. You should not have apache configuration in your .htaccess file. It should be in the actual apache config.

Re: Git: ignore file lines

#26
post #24

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.

Re: Git: ignore file lines

#27
post #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.

E.g. I build a new virtualenv from scratch for each deploy, so that would mean that the postactivate script would need to be accessed from somewhere by the build process.

Re: Git: ignore file lines

#28
post #14

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.

I actually prefer `git add -i` if I want more fine-grained control like that.

git add -i is a good idea, but the interface is just /atrocious/ - confusing, poorly worded, visually unattractive and hard to read (dark blue text is not very user friendly on a black background).

Re: Git: ignore file lines

#29

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.

I use git add --patch My teammates probably get tired of hearing it, but every time someone erroneously commits some file or line I advocate its use.

I've defaulted to this for some time now, and have no issues with keeping my own smattering of me-specific configuration overrides. Plus, there are a couple other times when being able to work through the patching interface is a handy skill to have.

Re: Git: ignore file lines

#30
post #24

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've not had that experience at all. For the times you know it would be tedious to add/ignore all diffs manually, you can just use the 'a' or 'd' commands to add or ignore for the remainder of the current file. I much prefer using 'add -p' every single time I commit.
Post reply on HN