Live data from Hacker News

Oh shit, git: Getting myself out of bad situations

ohshitgit.com

41–50 of 520 posts

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

#41

Earlier quoted context omitted.

If by "designed" you mean "picking a content-addressable DAG as an underlying data structure", then yes, it is really beautiful. If you mean "provide a sane level of abstraction over said data structure", then hell no!

I think git provides a sane level of abstraction. I don't think it provides the most consistent UI or helpful help, though. Once you move away from "learning git commands" to "learning how git works" and kind of figuring out which parts the commands refer to has helped also. That's still terrible though.

I find the only people who find Git to be confusing or frustrating are the ones that try to adopt complex workflows. I've taught marketing and creatives to use Git with no issues.

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

#42
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 remember the last time I made an irreversible change to the repo, or had an "oh shit" moment. And that's despite using some interesting git features.

- Staging individual files, folders, lines of code, or hunks is easy. Makes maintaining multiple trains of though / addressing bugs while working on other code a non-issue.

- It's easy to keep files uncommitted for long periods of time intentionally, without slowing down my workflow.

- It's much easier to get an overview of the changes I'm making.

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

#43

Earlier quoted context omitted.

If by "designed" you mean "picking a content-addressable DAG as an underlying data structure", then yes, it is really beautiful. If you mean "provide a sane level of abstraction over said data structure", then hell no!

I think git provides a sane level of abstraction. I don't think it provides the most consistent UI or helpful help, though. Once you move away from "learning git commands" to "learning how git works" and kind of figuring out which parts the commands refer to has helped also. That's still terrible though.

Most of the abstraction is fine. The staging area model is a total mess though. The way that staging interacts with other commands (e.g. stash) is constantly surprising.

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

#44
post #27
post #11

> Oh shit, I accidentally committed to the wrong branch! I find cherry-picking to be easier in this case. Just checkout the branch and cherry pick commits from 'wrong' branch. https://git-scm.com/docs/git-cherry-pick

But then those commits are still in the wrong branch. If I accidentally commit something to master instead of a development branch, I can't deploy master until my development branch is merged in, as the one commit isn't ready for live.

If you haven't pushed, it's as easy as resetting the branch to the last good commit. If you have pushed, well, it's the same, then push -f, and then making sure that all your teammates pull the fixed branch. If that's a situation you regularly find yourself in, protecting master from direct pushes and only doing PRs is a good solution (GitHub, BitBucket and GitLab all have tooling for this).

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

#45
post #36

Earlier quoted context omitted.

I'm planning on making a hard push for git on the team I just joined (that isn't using any VCS). This and OP are going in my bookmarks.

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 could run relatively in isolation from others, so they could get away with it, but they're looking to grow so I'm trying to push this stuff.

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

#46

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.

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

#47
post #31

We pushed large binaries into our git in the past. This was fine-ish as long as Git was hosted inhouse, but now that it's SAASed out, they are a huge pain in the rear. I've browsed through a few git guides, but can't seem to find anything that would let me: 1) Do something like "du -s *|sort -n" for the entire Git history 2) Let me "rm -rf --from-history-too", that would cause the remote repo to actually shrink in si…

I think you should be able to do something like this with

  git filter-branch
This won't be a terribly fun exercise, and could be very painful if your history contains a lot of merges. (should be easier with the cactus/rebase development model)

And of course everyone will have to hard-reset to the new branch.

I should mention I'm far from an expert on this. I've only ever used git filter branch on a handful of commits, and only based on examples provided by kind internet people. I certainly haven't done anything nearly as far-reaching as you're about to embark on.

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

#48

I like using IDEA, PyCharm's and Webstorm's "local history" feature to compensate for gaps in my git knowledge. A constant, instant backup of all files, independent of the repo, has been my saving grace for small projects.

I recently did something like that—I think I did a reset of the repo and lost all of my changes. Was able to piece it back together using local history. Took me another 20 minutes, but at least all of my data was there.

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

#50
post #31

We pushed large binaries into our git in the past. This was fine-ish as long as Git was hosted inhouse, but now that it's SAASed out, they are a huge pain in the rear. I've browsed through a few git guides, but can't seem to find anything that would let me: 1) Do something like "du -s *|sort -n" for the entire Git history 2) Let me "rm -rf --from-history-too", that would cause the remote repo to actually shrink in si…

Git bfg should do the job, it works well for that and to remove files with secrets... or really anything you want to pretend never existed in your repo :)

https://rtyley.github.io/bfg-repo-cleaner/

Post reply on HN