Live data from Hacker News

Git: ignore file lines

benmezger.me

31–40 of 40 posts

Re: Git: ignore file lines

#31
post #14

Earlier quoted context omitted.

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

I guess it's a matter of taste. I would find the context switching between the shell and the GUI more jarring than the usability of `git add -i`. Also, shell colours can be adjusted.

But in the end it's good to have multiple options.

Re: Git: ignore file lines

#32

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.

Magit in emacs is great for this functionality. It will even add just the selected region of the diff.

Re: Git: ignore file lines

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

¹ https://packagecontrol.io/packages/Transcrypt

Re: Git: ignore file lines

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

Re: Git: ignore file lines

#35
post #31

Earlier quoted context omitted.

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

I guess it's a matter of taste. I would find the context switching between the shell and the GUI more jarring than the usability of `git add -i`. Also, shell colours can be adjusted. But in the end it's good to have multiple options.

Oh I also prefer CLI, I just tend to use add -p instead.

Re: Git: ignore file lines

#36
post #27
post #9

Earlier quoted context omitted.

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.

I was talking about local dev install where you can activate postactivate script is run after you source activate or call workon. In prod, you will not be activating the env but running executables directly from the env.

ie, your process manager will call /path/to/env/bin/gunicorn and in this case, you'll have to configure the env variables here (in the process manager (supervisor)) config.

Re: Git: ignore file lines

#37

Earlier quoted context omitted.

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.

Then you've been lucky. Although if you show others on your team this approach, I think something bad is guaranteed to happen eventually.

Re: Git: ignore file lines

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

Re: Git: ignore file lines

#39
I'm still looking for an elegant way to reject commits whenever a certain pattern appears in one of the files to be committed (like "FIXME").

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.

Post reply on HN