Live data from Hacker News

Some bad Git situations and how I got myself out of them

ohshitgit.com

141–150 of 352 posts

Re: Some bad Git situations and how I got myself out of them

#141
lots of these are unnecessarily complicated:

> Oh shit, I accidentally committed something to master that should have been on a brand new branch!

    # disappear the last commit and all changes from it
    git reset --hard HEAD^
    # make a new branch using the last commit
    git checkout -b new-branch HEAD@{1}
> Oh shit, I accidentally committed to the wrong branch!

first, you don't need to git-add before and after stash, stash will save the working directory and the index (as documented in the DESCRIPTION of git-stash(1)). but for a more logical way:

    # disappear the last commit and all changes from it
    git reset --hard HEAD^
    # get onto the new branch
    git checkout new-branch
    # grab the stuff from what was on the old branch
    git cherry-pick old-branch@{1}
> Oh shit, I tried to run a diff but nothing happened?!

    git diff --cached
recommended reading for intermediate git users: the DESCRIPTIONs of all of these commands (git-reset(1), git-checkout(1), git-cherry-pick(1), git-diff(1)), and the entirety of gitrevisions(7).

Re: Some bad Git situations and how I got myself out of them

#142
git to me is a work of art. There is a lot of complexity underneath but the end user sees something that is simple, fast and easy to use. It scales depending on user needs and It's easy to reason about.

This is a feat of engineering, to take something complex and make it easy for anyone to undestand and use. It shows real expertise and deep understanding of the area.

In many ways it's a shining example against the 'culture of complexity' that we increasingly find ourselves in. Here rather than simplying the objective is to be to make thing as complex as possible, usually in pursuit of extremely niche use cases or because either the expertise or the interest to simplify is not there. If git was designed in this culture it would be fragile, full of buzz words, poorly documented and prone to failure, and something only a few self appointed experts could reason about and use properly.

Re: Some bad Git situations and how I got myself out of them

#143
post #130

Earlier quoted context omitted.

Its true -- and actually the well designed gui that accurately depicts the graphical state of your local repository makes it far easier to learn the concepts behind git than does the command line. Distributed vc is conceptually nuanced, but not overly complicated -- the complexity of git really is in the interface wherein you are asked to map command line syntax into abstract operations that manipulate a state that y…

Only for iUsers... Really searching for a Linux alternative !

Have you tried GitKraken? https://www.gitkraken.com/

Seems like there's a glut of these apps of late—not that I'm complaining! :-)

Re: Some bad Git situations and how I got myself out of them

#146

Earlier quoted context omitted.

"Not the friendliest of beasts" is putting it mildly. Git is basically Linus in a nutshell: abrasive, unforgiving, and behaving like an absolute asshole to any non-expert struggling user. Sure, engineers should probably get to know its quirks and learn to work around them because it's now ubiquitous in the field, but let's not pretend that there's something virtuous about it. This is a piece of truly terrible softwar…

> ... that just happened to win the PR battle ... Chalk that up to the power of fashion. Otherwise, people would use an SCM that doesn't destroy their work in the blink of an eye and actually has an API that deserves the name.

The only way to lose work with git is either to (a) not commit it or (b) run a garbage collection.

Re: Some bad Git situations and how I got myself out of them

#148
post #72

I can't believe no one has responded yet with "use a GUI". After gaining a basic understanding of how branches and merges work, and I do mean basic , I've never been able to screw up a local repo with a GUI client enough that I haven't been able to recover with the same GUI tools. I understand that people need to know how to use their tools, but for git most people can get away with the very basic usage that GUIs pro…

I have to disagree, I've seen people paint themselves into really hard to get out of corners by using GUI tools and not understanding the underlying tool. git GUIs are leaky abstractions that sometimes even change the meaning of core git concepts. I always recommend people start by using git at the command line until the have a solid understanding of how the tool works before switching to a GUI.

I completely agree with this one. I encourage our developers to always use the cli, even if they are not familiar with the core concepts of git. I see myself as a mediocre git user, but there are some situations, however, where I prefer to use a GUI for more complex operations, like staging/un-staging specific lines or create/apply patches.

Re: Some bad Git situations and how I got myself out of them

#150
One of my favorite teachers in school was a dude-bro programmer who pretty sure as younger than me. He'd spent a summer at Google and made us use git and gerrit. I'm honestly a much better programmer thanks to him. I'm still using the git cli to this day.

I also still say "new up" an object thanks to him. I'm not so proud of that one.

Post reply on HN