Live data from Hacker News

Things I wish everyone knew about Git (Part II)

blog.plover.com

1–10 of 148 posts

Re: Things I wish everyone knew about Git (Part II)

#3
> It is really hard to lose stuff

Furthermore I recommend turning off automatic garbage collection. Turning it off makes it even harder to lose things, and unless you have an insanely massive amount of churn, you really don’t need it.

https://donatstudios.com/yagni-git-gc

Re: Things I wish everyone knew about Git (Part II)

#4
post #2

"It is really hard to lose stuff" Indeed. This also means that garbage keeps piling up in git repos. This is how I make sure, I do lose stuff eventually: https://github.com/no-gravity/git-gc-all-repos.sh A script that goes through all my repos and performs garbage collection.

Disk space is cheaper than lost data.

Re: Things I wish everyone knew about Git (Part II)

#5
post #2

"It is really hard to lose stuff" Indeed. This also means that garbage keeps piling up in git repos. This is how I make sure, I do lose stuff eventually: https://github.com/no-gravity/git-gc-all-repos.sh A script that goes through all my repos and performs garbage collection.

I know your link says you don't want to do `gc --aggressive --prune all`, but for anyone who does: a) That still leaves objects referenced by the reflog, so you may want to `reflog expire --expire=now --all` first if your reflog is full of rebases etc that you don't need, and b) you may want to run gc twice because the second time compacts a tiny bit more than the first.

Re: Things I wish everyone knew about Git (Part II)

#7
A simple one is being able to write multiple messages (subject and body), e.g.

  git commit -m "subject" -m "a longer body"
or just running 'git commit' and using your text editor (subject first line, body after).

I've worked on too many repos with messages like "fixed the thing" where a few more sentences of context would've prevented headaches when trying to debug or change something.

Re: Things I wish everyone knew about Git (Part II)

#8
post #3

> It is really hard to lose stuff Furthermore I recommend turning off automatic garbage collection. Turning it off makes it even harder to lose things, and unless you have an insanely massive amount of churn, you really don’t need it. https://donatstudios.com/yagni-git-gc

Or committing large binaries frequently, but yes. Totally agreed.

GC manually unless you're dealing with scale where you know precisely how much it helps you. Otherwise it's safer and easier to not do it, and the disk space is utterly inconsequential (and trivial to find and `git gc` if it proves otherwise). You can afford a few more megabytes every year or so.

Re: Things I wish everyone knew about Git (Part II)

#9
post #6

"It is really hard to lose stuff" It is really hard to lose stuff that you have ever committed. It is really hard to lose stuff as long as you commit early and often. Uncommitted work is pretty easy to lose with 'git reset'.

... or with `git checkout` or with `rm` or `git clean` (for files not yet under version control).

Re: Things I wish everyone knew about Git (Part II)

#10
> But the old commit is still in there, pristine, forever.

> (Git will eventually throw away lost and unused snapshots, but typically not anything you have used in the last 90 days.)

Without having exlplained what a 'snapshot' is and what 'typically' means, it's pretty unclear whether the first statement is affected by the second, and if it were the first is incorrect, so I feel this clarification should be added to the list of things you want people to know about git.

Post reply on HN