Live data from Hacker News

Oh Shit, Git

ohshitgit.com

41–50 of 237 posts

Re: Oh Shit, Git

#41
post #6

Just delete the directory and clone it again.

This is what I do.

Even though I understand git really well it’s quicker to just blow it away and start again rather than accidentally make it worse realising you didn’t understand it as well as you thought you did.

Fortune favours the lazy.

Re: Oh Shit, Git

#42
post #19
post #16

For someone to get out of a mess they would have to know that they caused a mess in the first place! I'm starting to think trying to get people to use rebase and squash is a losing battle when they frequently just merge without pulling.

I got my team on side to use rebase/squash instead of blind merge commits after I showed them how much easier git bisect is to use when you have a linear commit history in your main branch. Now nobody wants to be 'that person' who breaks the bisect feature in case we urgently need it.

"git bisect --first-parent" gives most of the same benefits for teams that don't rebase/squash.

At least until someone does a foxtrot merge and then it never works again

Re: Oh Shit, Git

#43

My mental model of a git repo is basically a bramble bush with labels on it. The bramble stems and branches are the commit history (which may join and well as split, unlike a bramble). The labels are stuck to particular bits of the bramble. Some labels are even stuck to other labels! You can move the labels around, and you can glue extra bits of bramble to the tips of what you have. You can even hack about with the b…

Conceptualizing a commit graph with branch/tag labels is the easy part. What gets messy is operations regarding remote vs. local (as you mention) and regarding the various local state one may have (working directory, index/staging). Then there’s also the issues that arise with merging, but you have those with every VCS.

Re: Oh Shit, Git

#44
post #43

My mental model of a git repo is basically a bramble bush with labels on it. The bramble stems and branches are the commit history (which may join and well as split, unlike a bramble). The labels are stuck to particular bits of the bramble. Some labels are even stuck to other labels! You can move the labels around, and you can glue extra bits of bramble to the tips of what you have. You can even hack about with the b…

Conceptualizing a commit graph with branch/tag labels is the easy part. What gets messy is operations regarding remote vs. local (as you mention) and regarding the various local state one may have (working directory, index/staging). Then there’s also the issues that arise with merging, but you have those with every VCS.

I love mercurial’s solution of having phases for commits. Anything you created locally is Draft phase and can be mutated without “force”. Anything which was pulled or pushed is automatically marked as Public and is not easily mutated. Visualizing the commit graph also colors commits based on phase making it really easy to get a grasp of what’s going on.

Is there an extension or something for Git to have similar behavior to this?

Re: Oh Shit, Git

#45
post #4

Git is a reminder why even the best minds in software development sometimes really should talk to UX/UI people.

Git's UI/UX is one of the worst engineering sins to be committed in the last two decades, and this website shows why. Literally nothing about git is intuitive and the "underlying model" is entirely ad-hoc. Instead of celebrating how Linus built git in only a few days he should be castigated for knowingly setting up ill-conceived software to go viral.

Re: Oh Shit, Git

#46
post #22

If anyone is curious: git diff --cached is the same as git diff --staged. I don't know why they aliased them but I run git diff --cached very frequently and after seeing this post's reference to --staged I wondered what the difference was. Turns out there is no difference.

I use --cached as well but I think I will try switching to --staged since that name makes more sense to me. I similarly have gotten away from checkout in favor of switch/restore.

Re: Oh Shit, Git

#47
I think the steps under https://ohshitgit.com/#accidental-commit-master are wrong: it reverts the commit on the new branch -NOT on the master. This is because git branch auto checks out the new branch. You need to do

git branch NEWBRANCH

git checkout master

git revert —hard HEAD^

If you want to continue working on the new branch you do

git checkout NEWBRANCH

Re: Oh Shit, Git

#48
post #30

Earlier quoted context omitted.

Depends. Sometimes it's easier to tear down everything and start from scratch.

Isn't this what a `git reset --hard` does?

I've gotten out of sync with the remote where that would still fail and decided to just reclone. I think the reason it happened is git-history purists rewriting and pushing.

Re: Oh Shit, Git

#49
Another useful thing if you need to backdate commits for whatever reason are the GIT_AUTHOR_DATE and the GIT_COMMITTER_DATE environment variables, upon executing git-commit they'll override these fields in the commit to whatever date, time and timezone you specify. I use this sometimes when I'm making some previously private work public, and am redoing the commit history to make more logical sense to others who may read it.

Also useful are git-fast-export and git-fast-import, if you really need to delve into the inner details of a commit. For example, I had three separate but related git repos that I needed to merge, so I created a new repo with separate branches to hold each repo, merged everything manually, committed that to a new branch, then used export/import to edit the commit to have the tips of the three other branches as its ancestors. Maybe there's a better way to do this with other git commands but I found it easier just to delve in and edit the commit data manually.

Post reply on HN