Live data from Hacker News

.gitignore Everything by Default

packagemain.tech

151–160 of 185 posts

Re: .gitignore Everything by Default

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

For many years I've have a git-ignored ".not-committed" folder in all of my repos for throwing extra anything into. It's been a huge life saver!

[deleted]

Re: .gitignore Everything by Default

#153

Earlier quoted context omitted.

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.

You don't need to put the scratch directory in the committed gitignore file. gitignore files are recursive. So a common approach is to use a gitignore with * in the scratch directory.

Re: .gitignore Everything by Default

#155

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…

WTF? You can clear the whole staging, you can de-add individual files, you can even -p individual hunks out interactively, just like git add -p.

Re: .gitignore Everything by Default

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

For many years I've have a git-ignored ".not-committed" folder in all of my repos for throwing extra anything into. It's been a huge life saver!

i usually do "*ignorethis*", so a file with .ignorethis extension does not strictly have to be under a specific directory, this might save context somewhere. similar approach but yeah, a huge life saver!

Re: .gitignore Everything by Default

#157

It is weird that quite a few developers comes up with advices where they seem to come from a world where they work alone, have not work with enough people, or with enough projects. In this case, a `.gitignore_global` takes care of the usual suspects that he mentioned `.DS_Store files, IDE config, compressed files, etc.`. Even if something goes wrong, it is usually caught during the initial scaffold before critical fi…

Wow, thanks so much for . gitignore_global. Finally can have Emacs files ignored automatically in all projects. <3

Emacs can be configured to dump its litter into specific directories instead of in-situ with the files being edited.

Please do.

Re: .gitignore Everything by Default

#158

Earlier quoted context omitted.

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.

In magit press s to stage and u to unstage. Very intuitive.

You can also select specific hunks or lines within a hunk to stage/unstage.

Re: .gitignore Everything by Default

#159

  strict_ignore() {
    [[ -n "$1" ]] || exit 1
    local repo="${1%/}/"
    local ignore
    ignore=$(find "$repo" -path "$repo".git -prune -o -print \
               | sed "s|$repo||g; /^$/d" \
               | awk '{print "!"$0}' \
               | sort)
    printf "*\n%s\n" "$ignore"
  }
Post reply on HN