Live data from Hacker News

Oh shit, git: Getting myself out of bad situations

ohshitgit.com

151–160 of 520 posts

Re: Oh shit, git: Getting myself out of bad situations

#151

Adopted a git GUI years ago and haven't looked back. I get looks sometimes, but I can't help but gloat when I can stage and unstage individual lines in less than a second. I think anyone who uses the CLI is either trying too hard or hasn't realized the beauty of a git GUI. Takeaways: - My commit time is usually much faster than coworkers, with higher accuracy (less frequent accidental commits, etc.) - I don't remembe…

You're entitled to your own opinion of course, but you underestimate the efficiency of the command line, especially when you already have one open for other development tasks.

I use one or more GUIs for visualizing branches, and old branch cleanup, and yes, committing single lines from hunks that can't be split.

However for everything else CLI is fairly close to optimal, including interactive adding/rebasing, and don't want to use whatever shitty editor your tool has in it, I want to use vim with syntax highlighting so I can properly format my commit messages. Even something as simple as viewing a full commit is faster in the CLI because you can just pipe it to less or send it to an editor versus whatever tradeoffs a GUI has to make to stay performant, make use of screen space, etc.

One last tool is Fugitive. This blows away anything else I've ever seen for interactively traversing history at the line level.

Re: Oh shit, git: Getting myself out of bad situations

#152
post #36

Earlier quoted context omitted.

I'm genuinely curious how they manage source without any VCS. Is it just a bunch of zip files for old versions? No judgment, nobody is born knowing this stuff, just that I'm surprised to hear this is still out in the wild.

We SSH onto a server to do work and it seems we just make folders wherever for our individual projects. They do (nightly, I think) backups which is sort of a rudimentary version control. And while I'm told it exists, it seems the "dev" version of their website isn't used, so they just kind of add in their changes live; definitely a risky environment. They've had a small team for a while and most of their applications…

Yeah the "right way" to do VCS is definitely a lot of overhead for a team like that, but by the time you need to scale up (and by "up" I mean 3-6 people total who are committing code multiple times daily?) the business is likely so busy it's a HUGE uphill battle to implement something like that, especially since most of the people who let an environment like that happen will likely not be super familiar with Git/hg/TFS/whatever.

Re: Oh shit, git: Getting myself out of bad situations

#153

Adopted a git GUI years ago and haven't looked back. I get looks sometimes, but I can't help but gloat when I can stage and unstage individual lines in less than a second. I think anyone who uses the CLI is either trying too hard or hasn't realized the beauty of a git GUI. Takeaways: - My commit time is usually much faster than coworkers, with higher accuracy (less frequent accidental commits, etc.) - I don't remembe…

> I think anyone who uses the CLI is either trying too hard or hasn't realized the beauty of a git GUI. Or, you know, understands and thinks in the semantics of the underlying tool and is already working in other text-based tools.

Conflict resolution in a GUI with 3 way merge really beats out a command line.

Re: Oh shit, git: Getting myself out of bad situations

#154

Adopted a git GUI years ago and haven't looked back. I get looks sometimes, but I can't help but gloat when I can stage and unstage individual lines in less than a second. I think anyone who uses the CLI is either trying too hard or hasn't realized the beauty of a git GUI. Takeaways: - My commit time is usually much faster than coworkers, with higher accuracy (less frequent accidental commits, etc.) - I don't remembe…

What GUI do you recommend? My experience has been that GUIs are the easiest and fastest way to make a mess that can't be corrected without dropping to CLI or re-cloning. (I'm looking at you SourceTree). I've long recommended that everyone who uses git know how to use the CLI even if they don't use it regularly.

[deleted]

Re: Oh shit, git: Getting myself out of bad situations

#155
I too felt this way once, and I still have to think (or even lookup) about what the conventions are occasionally, but there really is a point in learning Git at which you realize there really are not many 'oh shit' situations in which you can find yourself and not be able to escape unscathed.

But beyond learning Git itself, you need to develop suitable habits for using Git that are appropriate for your development workflow.

One habit I've consciously developed is to use 'WIP' commits (i.e. a regular commit with "WIP: Rebase me!" on the first line of the commit message) instead of stashing. All too often a stash lives for much longer than you'd naively expect and stashes are much harder to work with than commits. Even if the modifications are applied right away, commits are nearly as easy to 'apply' as a stash anyways.

Re: Oh shit, git: Getting myself out of bad situations

#156

Maybe it's not worth being in there because of how simple it is, but I guess it would be useful for newcomers: # Oh shit, I've changed 200 files and want to revert to the state of this morning $ git add . && git commit # often. Very often. $ git reset --hard commit_id

Wait, aren't you committing and immediately orphaning that commit? I think you should create a new branch or tag before the reset, otherwise how are going to get it back? I guess you could rely on the reflog, but I don't think that's good practice.

lol, no, it's implicit there are many hours between the first command and the second one :)

It's purely commiting often to easily have checkpoints to revert to, nothing fancy (yet, incredibly useful).

Re: Oh shit, git: Getting myself out of bad situations

#157

In three years of using git I believe there is a single bad command that I could not undo: `git checkout -- somefile` The second worst thing I did is losing a commit in a `git rebase -i` but I was able to find it back with `git reflog`. Which makes me think that git is really well designed.

I recently had one of those holy-crap-what-did-I-just-do-I-lost-everything moments... But then realized that my scrollback had a list of files and my IDEs (PhpStorm and WebStorm) both kept _local_ revision histories and I was able to restore everything I had done.

I've been saved by the local history in IntelliJ more times than I would like to admit, heh.

Re: Oh shit, git: Getting myself out of bad situations

#158

I've said this before, but the business leadership, and tech leadership, need to think carefully about whether or not they need all of the power of Git. This sums up my concerns: ----------------------- Here are some minor failure modes I’ve seen with Git: 1. a branch that stays open for many months, perhaps even a year (for instance, at Maternity Neighborhood) 2. data is erased for good because someone makes a mista…

Great list. You'll face a predictable backlash by git fanatics, but the fact remains that git's surface area / complexity is way beyond the needs or wants of non-technical users. This is another good rebuttal to the supposed shortcomings of svn which make git necessary:

https://svnvsgit.com/

You're right about the joy that end users feel when they learn TortoiseSVN and are able to put what they see as "infinite undo" into practice so easily.

There was a sarcastic list of git koans, too, somewhere, which I found funny.

Re: Oh shit, git: Getting myself out of bad situations

#159
post #71

Earlier quoted context omitted.

What GUI do you recommend? My experience has been that GUIs are the easiest and fastest way to make a mess that can't be corrected without dropping to CLI or re-cloning. (I'm looking at you SourceTree). I've long recommended that everyone who uses git know how to use the CLI even if they don't use it regularly.

If you're on a mac, I can't recommend Tower enough. It's a paid app but well worth the money. Otherwise Git Kraken is a foss offering that is also excellent.

I want to second that. Also the integration with diff tools like Kaleidoscope is a nice touch. (Even though Kaleidoscope feels like abandonware at this point)

Re: Oh shit, git: Getting myself out of bad situations

#160

My last git mistake was pretty terrifying. I decided to try and go back to an old commit on a project on my local machine after about a days work. Somehow I ended up making the commit I wanted to revert to a new branch, then somehow tagged that branch with the name of the commit making git get angry and decide that branch wasn't valid. Then continuing in my ignorance I reset to that branch and tried to checkout only…

Before doing anything with git that you're unsure of and could have dire consequences, just clone the directory beforehand. Then run the git commands to your heart's content.
Post reply on HN