Live data from Hacker News

.gitignore Isn't the only way to ignore files in Git

nelson.cloud

61–70 of 188 posts

Re: .gitignore Isn't the only way to ignore files in Git

#61
Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`.

This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file).

With `.gitattributes` in the root of your project, you can just add a line:

`package-lock.json -diff`

Now, that file will still get staged/committed (which you want) ... but when you `git diff` you won't see the massive amounts of pointless diff in that file.

Re: .gitignore Isn't the only way to ignore files in Git

#62

The global/user wide exclude is a feature that should be more widely known. I frequently have people submitting changes to add their IDE/OS/AI/... files to every project's .gitignore. They are almost always pleasantly surprised when I tell them that they can add them to their standard configuration and have them ignored everywhere without bothering every project and without risk of accidentally committing them on a p…

You frequently having to tell people about a global configuration gitignore is an obvious consequence of "My general rule is that in-repo .gitignore should only be used for repo-specific things". It wastes less of everyone's time to just gitignore them in every project.

I’d really only like my projects to talk about things relevant to the project, instead of having to think about the fact that you might be using Qt Creator.

Re: .gitignore Isn't the only way to ignore files in Git

#63
post #60
post #54

Earlier quoted context omitted.

That's a very particular way to frame the few vs the many. If a single macOS user works on ten different projects, should all ten projects add that line, or may things be better off taken out of each project's hands and on that single user?

I mean sure, if you're this worried about ten bytes and prefer instead to spend time endlessly lecturing new Mac-based submitters about the additional overhead of supporting Mac-based submitters.

As a Mac user, you should tell them how to do a better job.

Re: .gitignore Isn't the only way to ignore files in Git

#64
post #49

Earlier quoted context omitted.

Fair, but it depends how uniform the culture is around a particular project. Is it haskell and everyone is using emacs? Sure, include those. But trying to chase the requirements of half a dozen different editors is silly.

That's the thing though, you don't need to do that. Whoever is using whatever editor can do it, so the effort is distributed to whoever cares to contribute. There is no meaningful penalty for it to be not up-to-date. There is only a benefit for people who come in when it's already configured, as they don't need to configure anything anymore. (I say that but I'm using a global ignore too for eg ai configuration like s…

The penalty is a long file full of cruft that's effectively impossible to ever clean up.

Re: .gitignore Isn't the only way to ignore files in Git

#65

Earlier quoted context omitted.

You frequently having to tell people about a global configuration gitignore is an obvious consequence of "My general rule is that in-repo .gitignore should only be used for repo-specific things". It wastes less of everyone's time to just gitignore them in every project.

This mindset is how you get lots of IDE/dev-env-specific/platform-specific cruft inside of repos instead of pristine repos. It makes both contribution and maintenance difficult over time. While less of an extreme issue as IDE/dev-env-specific/platform-specific hacks/scripts littering the repo, gitignore entries should be generally justifiable, not ever-growing cruft to be added by each developer specific to their sit…

[deleted]

Re: .gitignore Isn't the only way to ignore files in Git

#66

Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`. This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file…

> that is pure noise from a Git standpoint

It shouldn't be noise. Don't update it if you're not intentionally trying to, otherwise you're exposing yourself to supply-chain risk for no reason. If you are regularly getting unexpected `package-lock.json` changes then you are doing something wrong.

Re: .gitignore Isn't the only way to ignore files in Git

#67
post #66

Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`. This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file…

> that is pure noise from a Git standpoint It shouldn't be noise. Don't update it if you're not intentionally trying to, otherwise you're exposing yourself to supply-chain risk for no reason. If you are regularly getting unexpected `package-lock.json` changes then you are doing something wrong.

It's not about unexpected changes. It's about DX in git CLI. You don't want to see massive diffs that are basically unreadable for humans, you just want to see that the file changed.

Re: .gitignore Isn't the only way to ignore files in Git

#68
post #30

Earlier quoted context omitted.

Well, since I know what a delta is, and I know what an object is, I understand all of it.

Congratulations!

Learn what those two things are and you can join me in celebration!

Re: .gitignore Isn't the only way to ignore files in Git

#69

Earlier quoted context omitted.

You frequently having to tell people about a global configuration gitignore is an obvious consequence of "My general rule is that in-repo .gitignore should only be used for repo-specific things". It wastes less of everyone's time to just gitignore them in every project.

I’d really only like my projects to talk about things relevant to the project, instead of having to think about the fact that you might be using Qt Creator.

Eh. It's a tool, not a document. It should contain things that help development.

Re: .gitignore Isn't the only way to ignore files in Git

#70

Earlier quoted context omitted.

Mine is aux and I hide it by putting a .gitignore in it that just contains am asterisk (*), nothing else, that way it ignores itself and anything in it.

Does Windows still go crazy when making an “aux” or “con” directory or has this been patched?

It's never going to be patched because it's not considered a bug.
Post reply on HN