Live data from Hacker News

.gitignore Everything by Default

packagemain.tech

121–130 of 182 posts

Re: .gitignore Everything by Default

#121
post #14

Earlier quoted context omitted.

I use "git add ." (or rather -A), but I will always do a "git status" first to make sure I'm not doing something silly. Of course you still have to be careful about subdirectories, which is why I usually also do a "git status" again before committing.

git add . is nondestructive and reversible. I tend to do git add . and then run git status. I’m far more interested in confirming my mental model of what I am about to commit if I git commit right now than my mental model of what will be added if I git add right now. If I didn’t already have that muscle memory I might try to switch to git add -v . which would tell me what files it added. I’d argue that a sane git wou…

No, ”git add .” is not easily reverted, there’s no git sub command for de-adding files from the staging area. You have to copy the whole folder (hope you have enough disk space), checking out an older commit (hard), and copy specific files from the copied folder. Pita.

This is actually a general problem with git and most cli tools, where it would be possible and useful to undo an action, but the tool developer cannot be bothered to implement such time-saving feature.

Re: .gitignore Everything by Default

#123

Earlier quoted context omitted.

git add . is nondestructive and reversible. I tend to do git add . and then run git status. I’m far more interested in confirming my mental model of what I am about to commit if I git commit right now than my mental model of what will be added if I git add right now. If I didn’t already have that muscle memory I might try to switch to git add -v . which would tell me what files it added. I’d argue that a sane git wou…

No, ”git add .” is not easily reverted, there’s no git sub command for de-adding files from the staging area. You have to copy the whole folder (hope you have enough disk space), checking out an older commit (hard), and copy specific files from the copied folder. Pita. This is actually a general problem with git and most cli tools, where it would be possible and useful to undo an action, but the tool developer cannot…

    git reset

Re: .gitignore Everything by Default

#125
People need to learn to use .git/info/exclude WAYYY more!

You use Cursor which creates .cursor? Cool! Put it in .git/info/exclude. No need to pollute the project .gitignore with that. .gitignore is for artifacts that arise from the natural building and testing of the software, as well as any scripts in the repo.

Re: .gitignore Everything by Default

#126
post #66

Earlier quoted context omitted.

You can just add it in a user-level gitignore instead of ignoring it in every repo. See: ~/.config/git/ignore

yes, but user level is not a repo level

Yes, but this is exactly the sort of thing that should be a user-level configuration. A personal scratch directory has nothing to do with the repository itself and doesn’t belong in a repo’s .gitignore.

If it's only needed for one particular checkout, .git/info/exclude is the other obvious option.

Re: .gitignore Everything by Default

#127

Git already works like this. It won't commit anything unless you explicitly stage it first.

Yes, but people miss often what is committed, especially if the change is big.

Eh? You explicitly have to add files to the stage before git will commit anything.

Re: .gitignore Everything by Default

#128
post #10

This seems like bad advice. I've very rarely committed extra files by accident, but I would 100% forget to unignore files I meant to commit. If you're doing an initial setup step to gitignore everything, why not just do an initial setup step to gitignore the usual files? Make a template that you copy into all of your repos.

[deleted]

Re: .gitignore Everything by Default

#129
post #4

I don’t ignore by default, but only stage the items I explicitly want. I can’t tell you how many times I’ve been pairing with someone when they just say “git add .”, I’m always confused by that choice. I get it, but I’ve seen more problems arise from adding all than being consistently selective. To each their own.

"git add ." ... so annoying to watch people do that, when "git add -u" is right there ... and even when you tell them why it is a bad habit, they continue doing it. I can only assume, that it is due to overly relying on GUI tools for git, that they do not understand this, or due to not having had to switch credentials everywhere due to committed secrets.

Re: .gitignore Everything by Default

#130
post #4

I don’t ignore by default, but only stage the items I explicitly want. I can’t tell you how many times I’ve been pairing with someone when they just say “git add .”, I’m always confused by that choice. I get it, but I’ve seen more problems arise from adding all than being consistently selective. To each their own.

Lazygit[0] is ideal for quickly selecting files or lines you want to include in your commit. There are probably countless others. And `--patch` is also not that hard. [0] https://github.com/jesseduffield/lazygit

Magit of course also solves this very nicely.
Post reply on HN