14 ms·
Oh Shit, Git
- danjac 4y agoGit is a reminder why even the best minds in software development sometimes really should talk to UX/UI people.
- gpspake 4y agoIt's never too late. I think gitkraken fixed this problem
- petepete 4y agoGit was built with a very specific use case and aimed at an extraordinarily technical subset of users. It dominated the world despite the UX flaws, which suggests they really aren't that bad.
- hardware2win 4y agoI'd say that ppl got used to it and it is good enough + industry standard, so it is hard to migrate to something else Especially if you'd have to lose github, thats the real force If gh migrated to something else, then a lot of ppl would follow
- elsjaako 4y agoThese days when I have to use svn somewhere I use git as a client, because it works better for me. If you prefer you can use mercurial as a git client in the same way. Most of my git use stays local on my PC, uploading it to github or gitlab or whatever is a secondary concern for me.
- kasey_junk 4y agoIt dominated the world because GitHub was better than BitBucket and had more generous free levels. If only that wasn’t the case we’d all be using a sensible source control system now instead of one where people repeatedly say things like “if you just learn the underlying model…”
- samwillis 4y ago> GitHub was better than BitBucket and had more generous free levels GitHub for many years only had free public repos, not privet, BitBuckets USP was that you could have privet repositories for free. GitHub "won" because of the social aspect around it and the tooling for open source projects - it never had more generous free levels.
- kasey_junk 4y agoBitBucket limited the number of repos you could have while GitHub allowed you to have as many as you wanted so long as they were public. Which had the (intended?) effect of making it more useful socially.
- carapace 4y agoIt's not even an anecdote but, uh, I prefered hg to git until the day I tried to use it on a system with the wrong Python installed... (I like Python! But it's a scripting language, not a systems language. Also the "deployment story" is bananas.)
- elsjaako 4y agoI for one like how git works. Some of the command names are weird, but I know more sane names are being introduced (e.g. git restore, git switch). Yes, you need to follow a tutorial to use it effectively. Designing for beginning users is often detrementantal to advanced users, and I object to that being called "user friendly". I'm not very vocal about git usually because I'm not an expert I have no big complaints, and I'm not that interested in arguing about it. I think there's a lot of us that are perfectly happy with git; we just make less noise.
- rkangel 4y agoI'd argue the opposite - that the model was so good and so much better than anything else that it was adopted despite the UI/UX flaws. Things can be good, have a flaw and still be considered good. That doesn't mean that we pretend the flaw doesn't exist.
- GuB-42 4y agoMercurial is built on what is almost the same model and has what I think is a better UI/UX. Some people say that git is technically superior but you really need to be an advanced user for it to matter, or work on a really large project. At work, we switched from SVN to Mercurial, and from Mercurial to Git. Most people were happy to switch away from SVN, but few enjoyed the change from Mercurial to Git. Personally, it took me much longer to get used to Git than with Mercurial, even though Mercurial was my first DVCS. I now have a slight preference for git, but I am happy with either (just don't bring back SVN!). Why Git came to dominate and not Mercurial? I am not sure, but I don't think technical reasons explain everything. Its association with Linux probably helped a lot.
- rkangel 4y agoI was also a Mercurial fan who had to reluctantly accept the rise of Git. Git was always a bit quicker, but Mercurial was much more predictable until you really understood the ins and outs of Git. > Why Git came to dominate and not Mercurial? The answer is actually really simple and non-technical: Github. We take these feature rich online code hosting platforms for granted now, but Github was really the leading edge of the wave. It made it easy for people to work together on writing software so it had great takeup and started a Git snowball effect.
- frutiger 4y ago> Why Git came to dominate and not Mercurial? I was an early proponent of Mercurial over git. While they are similar, a few “minor” things made a big difference: Mercurial distinguished between branches and heads, whereas git did not. This added extra complexity. Git embraced checksums as identifiers while Mercurial provided local revision numbers, this obscured the mental model. Git is faster to pronounce than either “Mercurial” (which has a tricky vowel in there) or “hg”.
- toshk 4y agoThey are bad. Some concepts like rebase etc. I still don't understand. In software we often go for further complexity instead of less. I think because most of us who are the lead developers are often the most intelligent. And we often enjoy these complicated abstract models and they come easy to us. However in satisfying our own intellectual vanity we often don't see how many we leave behind. Which is good for our hourly rates, but less good for creating affordable and simple software. Anyway one of the main practical advantages git had was decentralized repos meaning you were not dependent on an external server which meant git was often much faster if working with in daily tasks compared to centralized versioning systems
- BossingAround 4y agoI'm sorry if this sounds arrogant, but if you don't understand basic Git concepts like rebase, I don't think you're in a position to comment on the architecture of Git
- toshk 4y agoThats kinda the point :). I've read this many times, but schopenhauer in german is more readable: https://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge https://stackoverflow.com/questions/804115/when-do-you-use-g...
- lawn 4y ago> It dominated the world despite the UX flaws, which suggests they really aren't that bad. No it doesn't. It suggests the other features are so damn good that it overcame the horrible UX.
- ReptileMan 4y agoSo was mercurial ... but it much more user friendly.
- pjmlp 4y agoIt dominated the world thanks to Linus cult (their hero can do no wrong), and being required for Linux contributions. I bet git produced by a no name Linus, in isolation not required by any major project, would have hardly been taken any major uptake.
- Jedd 4y ago> It dominated the world thanks to Linus cult (their hero can do no wrong), and being required for Linux contributions. I think parent's point is that that demographic is positively tiny, and there were plenty of other serviceable offerings around at the time. The claim stands - git won despite its UX flaws, which does suggest the alternatives, while serviceable, weren't sufficiently fit for purpose.
- pjmlp 4y agoThe alternatives weren't required for collaboration in Linux development.
- Jedd 4y agoYes, but again, the number of people collaborating on Linux kernel development is truly tiny. I think perhaps you're over-estimating the network effect for VCS's -- having multiple version control binaries on your machine is low cost, and aliases can, up to a point, give you a consistent interface to them all. The highly sophisticated demographic of kernel developers would not have been at the pub insisting that their friends drop svn and use git (exclusively!), anymore than they would have been trying to get any other projects they worked on to adopt bitkeeper previously. The fact that bitkeeper was required for 'collaboration in Linux development' for so long supports this position.
- pjmlp 4y agoBitkeep wasn't free beer and its adoption was widely controversial, until Git was born given their change of heart.
- koonsolo 4y agoI've worked with CVS, Subversion, Bazaar, Visual SourceSave, Team Foundation Version Control, Mercurial and Git. The worst systems are the Microsoft ones, but the one with the most complex interface is definitely Git. I would argue it won because of github. I'm using Git because of that, but still prefer Mercurial in every way.
- hardware2win 4y agoGit and regex
- kcl 4y agoGit'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.
- flohofwoe 4y ago> for knowingly setting up ill-conceived software to go viral I doubt that was the intention. Linux just needed a versioning system tailored to its needs, and that's exactly what Git is. Can't blame its creators that other people used it for scenarios it wasn't built for.
- kcl 4y agoRight, you are the cop-out I am complaining about. Linus is the premier figurehead of the premier open-source project. When a build tool he made for that project goes viral it isn't an accident. If it was anybody else's pet versioning control system would we even be talking about it?
- salamander014 4y agoIf it went viral, yes. I agree most of the time I feel like the world is run by evil folks twiddling their fingers in secret. This is not one of those times. I agree there's a chance there are better word choices or feedback for some commands, but overall once you 'learn the language' it really is a lean, mean, well designed piece of software. Folks that complain about the UI/UX don't realize it wasn't designed for less technical folks. It was designed for the folks who needed it. It's success must at least partially prove that the UI/UX is not 1/10. Any real engineer will tell you, there are times where they wish they could do something better but the requirements and constraints left them making tough decisions, and that doesn't mean they aren't proud of their work. It's success is also partially due to the fact that it is lean and mean, which allows it to be applicable to nearly all software projects of any flavor. So I don't understand why folks argue it could have been done better. If it was 'better', in my view it wouldn't have been successful. The success was driven by it's succinct design and Linus' take it or leave it attitude. Technically accurate studio monitors don't sound as pleasing to the ear as good well tuned speakers. But they are exceptional at the job they were designed for. This is like that.
- ReptileMan 4y agoWe had Mercurial but it died, not with a bang, but with a whisper ...
- Beltalowda 4y agoMercurial is still actively developed, and isn't really "dead", although it did lose a lot of popularity and "mindshare". Projects like Firefox and nginx use it, although others like Vim and Python switched to GitHub. I don't know if Facebook is still using Mercurial internally, but for their public stuff they use GitHub. I think that if GitHub had supported Mercurial like BitBucket or Google Code it would still be a lot more popular, but ah well...
- throwaway09223 4y agoIs it, though? I'm not so sure. Git has enjoyed overwhelming success, which would seem to empirically indicate that it's done something right in terms of design Perhaps the obviously wrong UX/UI isn't wrong? Perhaps UX/UI people aren't good at designing interfaces for experts?
- xigoi 4y agoGit has been successful despite the UI, not because of it.
- throwaway09223 4y agoCan you substantiate your opinion? It's open source, so why hasn't an alternate interface taken over?
- lolinder 4y agoBecause standardization matters and the first thing to become the standard is extremely difficult to unseat.
- throwaway09223 4y agoBut some of types of things have in fact changed, sometimes for seemingly trivial reasons. For example, the master/main branch shift. Everything broke when that change was made, but it happened and it wasn't a big deal. I'm not seeing the difficulty here. It seems that a more reasonable interpretation is that git has the type of interface that is hard to learn, but intuitive once learned.
- xigoi 4y agoThe master/main shift was fueled by political correctness. If “master” wasn't a synonym of a word associated with slavery, it would've never happened.
- 4y ago
- BossingAround 4y agoTo me, Git is designed in a very nice and understandable way with a terrible terminology. I might be an exception though.
- huachimingo 4y agoBasically all of the UNIX world.
- elcapitan 4y agoHonestly, when I think of software that I suffered using recently, then UX/UI people are usually the reason, not the solution for that suffering.
- vaylian 4y agoPlease correct me if I'm wrong, but Linus probably didn't plan for git to be adopted by other people than just kernel developers. Because that was what git was created for originally.
- agumonkey 4y agoWhat I don't get is that the UX problem is not hard. I still like the underlying commit tree model a lot.. it's just some commands that are not clear enough (reset has 5 meanings and can backfire quickly). Maybe it's just retrocompatibility inertia.
- seadan83 4y agoI recommend you create aliases. I've got a 'git-squash' 'git-back' and 'git-update' aliases created, I almost forget they are not part of core git. Combined with scm-breeze that allows files and branches to be referenced with numbers... it's really fast and powerful
- duped 4y agoMore a reminder that UX/UI is a lot less important than speed and functionality for professional work.
- shmops123 4y agogit reflog has saved my ass so many times. I didn't know some of these other tricks, thanks for posting!
- amai 4y agoIf you stick to master-only development things like commiting to the wrong branch can't happen: https://medium.com/@mattia.battiston/why-i-love-trunk-based-development-641fcf0b94a0 https://medium.com/@mattia.battiston/why-i-love-trunk-based-...
- coldblues 4y agohttps://www.youtube.com/watch?v=3mOVK0oSH2M https://www.youtube.com/watch?v=3mOVK0oSH2M Every Git novice should check out this awesome introductory video ;)
- ChrisMarshallNY 4y agoI love this resource! Thanks for posting it!
- flemhans 4y agoJust delete the directory and clone it again.
- JoeAltmaier 4y agohttps://xkcd.com/1597/ https://xkcd.com/1597/
- david_allison 4y agohttps://ohshitgit.com/#fuck-this-noise https://ohshitgit.com/#fuck-this-noise
- 5e92cb50239222b 4y agoOr you can spend some time once to understand how git works, and never run into a similar situation again. git is built on a beautiful and very simple model, and it's easy to unbreak the repository 99% of time if you understand it (and I'm saying this as a very mediocre programmer).
- sdevonoes 4y agoDepends. Sometimes it's easier to tear down everything and start from scratch.
- leoff 4y agoIsn't this what a `git reset --hard` does?
- sethammons 4y agoI'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.
- solardev 4y agoThat just resets to your last local commit. To sync back up to the remote, you need at least do a git reset origin/HEAD --hard (and capitalization matters, I don't know why). But that doesn't work if you rewrote history in some way (I'm not sure why that's even possible). In that case your local git can get pretty messed up, some gui tools (IntelliJ) start to bug out and fail to diff properly, and it's easier to just start over. After ten years of using git, I've more confused by it than ever. People here keep talking about mental models, but I've read a shit ton of docs on it and am still totally confused. Probably some of us just aren't smart enough lol.
- me_bx 4y ago'How to undo almost anything with git' [0] is a similar resource, worth bookmarking in my opinion. [0]: https://github.com/blog/2019-how-to-undo-almost-anything-with-git https://github.com/blog/2019-how-to-undo-almost-anything-wit...
- edf13 4y agoMost excellent!
- eterm 4y ago> This usually happens to me if I commit, then run tests/linters... and FML, I didn't put a space after an equals sign This is why it's good to put the linting in a git hook on commit or stage, so you literally can't commit without being formatted correctedly.
- neallindsay 4y agoI generally don't like putting linters on commit hooks. Commits are easy to change and I think people would be better off making more of them. If your lint ends up taking a long time it will discourage frequent commits. Also, unless you jump through a lot of hoops, linters generally run against what's on-disk instead of what's actually going into the commit. So checks that run at commit time discourage partial adds.
- cesnja 4y agoI dislike that approach as it slows down committing. Preferably linter should be integrated in the editor and there should be one in the CI pipeline, but the steps between writing code and pushing it into CI should be as quick and smooth as possible.
- srvmshr 4y agoNGL, I have made (almost) all of these mistakes at some point. I am sure most others would have as well. Pretty nice compendium
- cdolan 4y agoThe best part is the header alert - if you don’t like the profanity, check out dangitgit.com!
- needle0 4y agoI liked how the Japanese translation of the page retains the two versions, but the language difference made the variants pretty much pointless, because there are hardly any "profane" words in Japanese that are offensive enough to warrant censoring by their utterance alone. (There do exist a group of offensive-enough words that relate to class/race discrimination, but no equivalent of a censor-worthy 'shit' nor 'fuck'.) The 2 Japanese translations are merely written as one mildly colloquial version vs another very-slightly-less-colloquial version.
- somewhereoutth 4y agoMy 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 bramble, but this is not recommended. Label moving often happens automatically, e.g. when 'growing' a bramble tip. It gets interesting when you compare two brambles (e.g. remote and local repos). You might determine that one bramble is identical to another, just with the labels moved. Or one bramble is the same as the other but with extra stems added. Or both brambles had a common ancestor bramble, but now they both have extra stems. Or perhaps they are completely irreconcilable. Better visualisation tooling would help.
- bhrgunatha 4y agoLearning the underlying model behind git is well worth the effort. For me watching Steve Smith's talk - Knowledge is Power: Getting out of Trouble by Understanding Git - was a lightbulb moment. Here's a 2019 presentation of that talk. https://www.youtube.com/watch?v=fHLcZGi3yMQ https://www.youtube.com/watch?v=fHLcZGi3yMQ
- tharkun__ 4y agoI think this is what can confuse people. We have to face the facts that not everyone will need or be able to grok all of what goes on in git and what makes the car go forward. We can all drive that car still! Take the recursive merging stuff around minute 39. Do I need to know why git's model for merging is so much better and how it works its magic? I don't think so. It's an implementation detail. Do I need to know how a gearbox works to drive stick shift? I have never thought of git as a bramble (tree worked fine for me :)) but the thing I always tell people about too is the labels part. What I think is enough for people to realize is that it's just like say SVN or CVS or any other source control mechanism in that there's a tree (bramble) of commits and then every commit can just be pointed to by a label. I can move those labels around any which way I want. Everything else follows from that on a surface level that is the only thing required to work with git in most situations, including some advanced ones. You don't need to know why certain operations in git are faster, better, have less conflicts or how they work internally. You just need to know what they do and when to apply them. I don't need to know why I can't make my car start or switch gears without pushing down the clutch. I just need to know when to push the clutch, i.e. if I want to start the car, push it. When I want to switch gears push it (well, mostly, on cars you want to last a while still lol). Of course some people won't even be able to learn how to drive stick shift and can only ever drive automatic.
- havblue 4y agoFor 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.
- cube00 4y agoI 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.
- timerol 4y ago"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
- sethammons 4y agoI loath rebasing. Squash merge into the main branch after tests are green. Bisect still works.
- nickjj 4y agoIf 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.
- somehnacct3757 4y agoI 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.
- rchard2scout 4y agoIIRC, it used to be --cached, and only recently has --staged been added as an alias, because staged makes more sense for users.
- benreesman 4y agoIt always amuses me that when Linus presents git to “the Google audience” they objected to the complexity, those people are in fact elite, but measured against what? The TailScale people? The TS people are ex-Google in some places and early-Nix in others, either way no one to fuck with. I’m frustrated if I take a day to work out some something that Jeff Dean mentioned to, uh, a friend, and it took me a day to work it out. @bradfitz works on TailScale, there’s also a reason he’s a chapter in a book. @jwz is better, by so little you’d never notice, so his chapter is cooler. What book are you in?
- chairmanwow1 4y agoI honestly don’t understand the context around this comment or how it relates to the article
- benreesman 4y agoIt’s admittedly a snippy, snarky, kind of cryptic comment and I probably deserve more downvotes than I got on it. In a more measured tone: there is, in my opinion, a kind of creeping anti-intellectualism that’s been slowly-but-surely gaining ground on HN for the last 5-ish years. We used to just really openly admire and respect iconic pros in this business, we used to openly acknowledge that some of the software work we talk about is pretty friggin elite and few of any of us will ever even work on some of it. Whether it’s Linus or the TailScale pros or John Blow, I’ve seen people get gang-tackled by the “no one ever uses this LeetCode stuff in a real job” crowd repeatedly in the last week. Knowing how to use “git reflog” to do surgery on a fucked-up repo isn’t necessary every day, but when you need it, you need it bad, and there’s nothing outdated about how knowing how the damned tools work.
- ilvez 4y agoI have used this resource, until common stuff has burned into brain "choose your own git adventure": https://sethrobertson.github.io/GitFixUm/fixup.html https://sethrobertson.github.io/GitFixUm/fixup.html
- splatcollision 4y agoCame here to post this - better than the link under discussion above. The interactive steps through a problem helps a ton for diagnosing the right steps to fix something!
- samatman 4y ago`git commit --amend :x` is faster to type, stopped using the --no-edit flag once I realized this.
- asicsp 4y agoSee "Flight rules for Git" for more: https://github.com/k88hudson/git-flight-rules https://github.com/k88hudson/git-flight-rules
- raju 4y agoWhile I'd like to think that this is _somewhat_ useful, I am a little hesitant. The issue I see with these bite-sized recipes is that there is no context, no place for nuance, and no hint that the behavior you see might be different for a variety of reasons. Take the following for example: > Oh shit, I need to change the message on my last commit! > git commit --amend It's important to realize here that if you are simply trying to edit the last commit message, you *should not* have anything in your index (that is, staged). Otherwise those changes will be recorded in the amended commit! What Git does is essentially move all the changes recorded in the commit you are amending _into_ the index, and then run `git commit -m <amended-message>` ... so if you have files in there, those will get mixed up with the ones in the commit. Here's another one: > Oh shit, I accidentally committed to the wrong branch! > A lot of people have suggested using `cherry-pick` for this situation too, so take your pick on whatever one makes the most sense to you! Umm ... No! The solution proposed (with `git reset --soft`) and a cherry-pick are NOT the same! Not even close! You will produce two completely different histories. This final one, given when this page was written, _may be_ understandably incorrect > Oh shit, I need to undo my changes to a file! > `git checkout [saved hash] -- path/to/file` There is the introduction of a new command called `git-restore` (https://git-scm.com/docs/git-restore https://git-scm.com/docs/git-restore) that (thankfully) is named more appropriately—it "restores" a file. I wrote a thread on it on Twitter, so if you are curious perhaps this will help: https://twitter.com/looselytyped/status/1501934009370042371 https://twitter.com/looselytyped/status/1501934009370042371 *Shameless plug for my book* My book, Head First Git, was published by O'Reilly this January. I posted a submission here on HN about it https://news.ycombinator.com/item?id=30072348 https://news.ycombinator.com/item?id=30072348 so if you want any details feel free to peruse that. Some links: - Amazon: https://www.amazon.com/Head-First-Git-Learners-Understanding/dp/1492092517 https://www.amazon.com/Head-First-Git-Learners-Understanding... - O'Reilly's online platform (Needs subscription): https://learning.oreilly.com/library/view/head-first-git/9781492092506/ https://learning.oreilly.com/library/view/head-first-git/978... - Companion website: https://i-love-git.com/ https://i-love-git.com/ (Edited for formatting)
- toddm 4y agoI've long considered git to be a wrapper around cvs designed to make me feel stupid.
- jmclnx 4y agoI liked CVS/RCS and still use RCS for local items. At worked we use git and I like it better than other alternatives (except RCS). My only complaint I have for git is it does not support $Id$ and other RCS variables. IIRC that was by design.
- SubuSS 4y agoI think the steps under https://ohshitgit.com/#accidental-commit-master 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
- dundarious 4y agoThe steps I see on the website are: git branch some-new-branch-name git reset HEAD~ --hard git checkout some-new-branch-name Which is correct, assuming master is already checked out. 0. prior state is that we're on master and have committed something that should have been on a branch 1. create a new branch that is identical to master (i.e., contains the commit) -- note this does NOT checkout the new branch (`git checkout -b some-new-branch-name` would do that) 2. reset current branch (master) to point at the commit before (i.e., strips the commit from master) 3. checkout the new branch to continue work there At the end, master doesn't contain the commit anymore, and the new branch does. It's all correct.
- lvass 4y ago>The command’s second form creates a new branch head named <branchname> which points to the current HEAD, or <start-point> if given. [...] Note that this will create the new branch, but it will not switch the working tree to it; use "git switch <newbranch>" to switch to the new branch. Source: git branch --help
- comment500 4y agoAnother 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.
- lloeki 4y ago> 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 Similar story here: at a previous job we had a monorepo with a Rails app and Rails engines extending its appearance and behaviour and per customer. At some point the architecture became problematic and we moved towards a shell app, a core engine, and extension engines depending on the core. We refactored code to that end, and "forked" the original monorepo into multiple clones, one per component, then stripping the other components in each one, ending up with 1:1 repo/gem/component. This worked for a while, easing a lot of issues we had previously, allowing for proper dependency expression, independent development and releases... Everything was great and we lived happily ever after. Then much later we hit a snag (I can't exactly recall what that snag was, IIRC it was not technical but organisational). So we looked at options and decided to merge into one single repo again. To that end we could do a big code drop, starting afresh, but (again I can't recall why) there was a need/requirement to keep at least some git history. But at that point, "some" ends up ~== "all". So I devised a plan. I git init'd a blank repo, added each one of the repos as separate remotes, and fetched each of them. Thus all git objects of all these repos were present. Then I checked out each one of these remote's master as a separate branch, created a subdirectory with the component name, moved every file for that checkout into that directory, and committed that. This way a) each project could live separately in the new monorepo and b) there would be no conflict for a merge. Then came time for the merge. Two options: a) perform N merges subsequently or b) perform an octopus merge. a) just felt wrong and ugly, so I decided to try if I could work b) out, but I ended up not being able to achieve that with porcelain commands as git was being too smart and attempted to look into the history for some reason I can't recall which produced senseless conflicts (IIRC git merge isn't entirely assymetric) So, since merge commits are merely commits with more than one parent I figured out I may be able to do that with plumbing commands instead. So the steps were: - for each branch, check out content (but without moving the current HEAD, so, actually, export the git tree corresponding to a specific ref/sha) - add all that to the index - create a merge commit object with each branch's sha as parent And it Just Worked, with the bonus that since up til the commit where we forked, each branch had common parents that were untouched, and commit history properly zipping up, by git's design, which is really a DAG of commit objects.
- wozer 4y agoGit is fast and powerful. It is considerably more powerful than most teams need.
- chillage 4y agoI avoid using git command line for all the reasons above Personally I use a UI for git which basically solves all of these problems. All the branches and commits are visible. If you want something somewhere, right click on it and you'll get all the available options. Nothing to memorize and everything is available! My own favourite after testing out a few is SmartGit, but it's paid so not for everyone. There are lots of free git UIs out there as well, but what I like about SmartGit is that it's completely full featured - every obscure git command is available somewhere - so I have never ever need to use git command line when on my local machine, not even for these obscure things like resets, rebase, cherry pick, squashed commits, etc you name it. Also SmartGit is cross platform so I can use it anywhere
- deleted 4y ago[deleted]
- rubyist5eva 4y agoI’ve been using git command line for over a decade. I know the vast majority of options and know how to bail myself out when things go awry. I’m the guy that people come to when they bork a rebase. I still prefer to use Sublime Merge, I’ve tried almost every git gui out there and that’s the one that “stuck” and I rarely use the CLI. I’ve ever used and it takes so much pain out of coming up with all the crazy command lines and all the switches.
- medv 4y agoI didn’t get it. I don’t consider myself as git expert but almost all from the site is really simple. With basic knowledge of git is enough.
- ToddWBurgess 4y agoJust curious, are people here still using master or did you migrate to main?
- kingkongjaffa 4y agoEverything repo is main now. The name change was a complete non issue.
- deleted 4y ago[deleted]
- shikoba 4y agoI saw no reasons to change.
- foobarbaz33 4y ago"using master" can imply being a leech. You should replace it with "working with master". "people here" could be interpreted as "you people". Please remove it from your comment.
- deleted 4y ago[deleted]
- lurker137 4y agoFor anyone who is hesitant to spend time learning the git cli like I was, just spend an hour on this interactive tutorial [1] and I guarantee you all of these solutions would have come to you easy https://learngitbranching.js.org/ https://learngitbranching.js.org/
- hugodrax157 4y agoSlightly orthogonal but a less destructive way of 'Fuck this noise' is to use worktrees. They were a game-changer for me. I often have several tasks on the go and it's really useful to have different branches in different directories and not have to stash changes if I need to quickly switch to a different task.
- saboot 4y agoWhat's the solution to "I accidentally committed a GB file and pushed it, now everyone has it"?
- layer8 4y agohttps://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-the-git-repository https://stackoverflow.com/questions/2100907/how-to-remove-de...
- olvy0 4y agoI second the recommendation to use git rocket filter [1] from this link. A guy in our team committed a big file unnecessarily into the repo which already had a year's history behind it, and it was only a month later when I found out. git rocket filter filtered it in a few seconds. Since all team members had already gotten it, I ran it on all their repos to verify it's gone, and ran the usual git gc incantation [0] to clean their repo. [0] https://stackoverflow.com/a/29203553 https://stackoverflow.com/a/29203553 [1] https://github.com/xoofx/git-rocket-filter https://github.com/xoofx/git-rocket-filter
- saboot 4y agoThank you, this looks promising
- gpspake 4y agoI find people are religious about being git cli purists and only interacting with it in this black box (the terminal). On top of that a lot of people stop learning git after add commit push pull branch and merge so concepts like rebasing and cherry picking are scary. In this day and age we have state of the art GUI tools that change the game and allow git users to see and interact with the state of a git repository in real time. It's a great way to demystify things like rebasing and interactive rebasing because they show you what's happening in a modern UI designed specifically for git. I often suggest git CLI purists to get something like git kraken and just use it as a visual dashboard. Watch what happens when you run git commands. You can see everyone else's remote branches and have a much better idea of what's going on than you can without it. I've worked on teams that just didn't rebase at all and I think people are oblivious to the mess they make on branches with their chaotic merge strategies. These days, I tend to envision the state of the branch that I want and make that happen. It's so easy to create a new branch before I do anything that if I think something might go south, I just hard reset to my previous state (a branch I created right before the operation) Gitkraken also has an undo button that handles all sorts of scenarios and I rarely click it without getting exactly what I expected.
- emeraldd 4y agoAs a counter point. Every time I've seen people get themselves into trouble with git has been when they are using a GUI tool. I have yet to see a gui tool that they can use to get themselves back out of it. There's a lot of value in knowing your way around the command line side of git even if you regularly use gui tools to interact with the repository.
- jgoodhcg 4y agoI've had the exact opposite experience. I've had to bail out cli purists because they just can't see what went wrong. Objectively git kraken has more visual information density. To get the same information on the cli requires multiple commands and the user has to hold the information I'm their head between the commands. Git kraken's buttons are also tightly correlated to commands and you can even bring up a window that shows what cli commands are being run under the hood.
- dimgl 4y agoIdk, am I the only one thinks Git is really not that hard? At all?
- nocman 4y agoNo. (edited: by that I mean you are not the only one)
- zach_garwood 4y agoIt's certainly easier than SVN. I won't go back, you can't make me!
- pmoriarty 4y agoIt would be nice to see something like this for Magit. Also, the fact that this is so complicated and that this document is as long as it is is strong evidence that git is just poorly designed from a UI standpoint.
- revskill 4y agoOne of my favorite ones is git stash, but it's not used here.
- dahart 4y ago> [git reflog … git reset…] You can use this to get back stuff you accidentally deleted Pro tip - this is true for commits, but not for accidentally dropped stashes. This is why it’s better to commit first, branching if necessary, than to stash. “If you mistakenly drop or clear stash entries, they cannot be recovered through the normal safety mechanisms. However, you can try the following incantation to get a list of stash entries that are still in your repository, but not reachable any more [git fsck…]” https://git-scm.com/docs/git-stash https://git-scm.com/docs/git-stash > Oh Shit! I accidentally committed to the wrong branch! [git reset … git stash …] A lot of people have suggested using cherry-pick for this situation too Because of the above warning about stash, cherry-pick is indeed a bit safer and more easily recoverable if something goes wrong when moving to the other branch. This particular situation isn’t dire given the premise that you already committed, so the reflog can be used. The situation where it’s more important is if you’re sitting in the wrong branch, have uncommitted work, and git won’t let you switch branches first. In that case, committing first into the wrong branch is recommended over stashing and switching branches, even though it’s slightly more work. I’ve actually watched people mess this up and then get frustrated with the magic incantation fsck stuff and give up and spazz and nuke their repo instead, while shouting “wait! no no no no…” over their shoulder. Stash is convenient sometimes, but never necessary, always less safe, and there are always commit flow alternatives. This is why I avoid it myself.
- rr808 4y agoThis is my main reason to use Intellij - it tracks all changes without having to commit them. There must be a vscode plugin to do the same, but I dont know of it.
- klyrs 4y agoMy worst git disaster was when I attempted to, iirc, stash a half-completed merge. Maybe I tried to pop the stash; I can't really remember why this seemed like a thing I should do. I've always felt like stash was made of gum and duct tape, and whatever sequence of operations I performed completely destroyed the repo. It's one of the very few times I've ever deleted the directory and started afresh, past the first few weeks of learning git. Stash is effectively equivalent to git switch -c stash-branch-$i git commit -am stashed git checkout $currentbranch so I use that instead. Only instead of an anonymous name, I pick something sensible in case I get distracted and return to the work later. Also, it means I don't ever need to commit to the wrong branch -- `switch -c` carries uncommitted changes along. Sometimes cherrypick isn't a fine enough granularity, and I'll use difftool to distribute changes between two branches.
- deleted 4y ago[deleted]
- at_a_remove 4y agoMy first introduction to git was ... well, the professor's solution to not having a place to upload. Given that the vast majority of the students involved had done almost no programming before, it didn't go so hot. I managed. My first "production" introduction to git was really about someone polishing their resume and chanting magic words at me. Merges ... happen? Who decides whether Bob or Cindy's code is used here? It just happens okay. Then I bought some books on git and was pretty unhappy with how arcane the naming was. How is "reflog" the correct and intuitive choice for "undo"? Was there something I wasn't understanding? No, I'm just supposed to accept that. Thankfully, my current programming gig is simple enough that I don't have to look at git. Either eventually sanity will come to the naming of commands or something else will appear, just as it has for every other tool.
- nocman 4y ago> How is "reflog" the correct and intuitive choice for "undo"? Was there something I wasn't understanding? No, I'm just supposed to accept that. Actually your initial intuition was correct. There are things you obviously don't understand about git. "reflog" is short for reference log. As "git help reflog" will tell you: Reference logs, or "reflogs", record when the tips of branches and other references were updated in the local repository. It isn't arcane. It's perfectly logical choice for what the "git reflog" comand does, as explained in the man page: "This command manages the information recorded in the reflogs." Now if you don't know what a reflog is, you will be confused by this. But the solution to that is for you to learn what a reflog is. And yes, in order to use git well you need to have at least a rudimentary understanding of how it works. I know that some people do find git hard to understand. Often that is because they want it to work a different way than it does. But git is a fairly complex tool designed to solve a very complex problem. It does an outstanding job of doing what it was designed to do. However, if you are not willing to invest the time in understanding git to a minimal level (and many people aren't), you will find it to be confusing. There is no need for "sanity" to "come to the naming of commands" for git. The commands already have sane names. But if you don't know what those names mean, it will seem to you as if they are in a foreign language. Most of the confusion people have with git is due to them having an insufficient level of knowledge of how it works. Again, if you want to use git well, you have to gain that minimal knowledge . If you are not willing to do that, then you should either become willing or choose to use some other version control program that is more to your liking.
- Egoist 4y agoSwear free version at: https://dangitgit.com https://dangitgit.com
- motoboi 4y ago> # remove the last commit from the master branch > git reset HEAD~ --hard I see this all the time, this "commits ON a branch" mentality. My secret to understanding git is: branches are just adresses, labels, pointers, aliases to commits. A branch is just a label pointing to a commit. So, you don't "remove (or add) a commit from a branch", you change where a branch point to. Commits are tree nodes, they have a parent and they can have children. If you point a branch to a commit, you can now think of a branch as that commit and its parent commits. So, `git checkout master` is just `git checkout <commit>`. But in a smarter way, as git is storing this as a special reference for you. If you do a `git checkout commit-ref` git will warn you that you are now working in a commit tree without a special name (detached). Oh, I wrongly "commited to master". Ok, just point master back to the previous commit. Oh, I want master to point to another point in time. Just find the commit reflecting that point in time and `git switch master; git reset <commit ref>`. Reset should be called "point the current branch to this commit and make the working tree reflect the state of the code at that commit".
- zoomablemind 4y ago>...So, you don't "remove (or add) a commit from a branch", you change where a branch point to. Well, once committed, the corresponding deltas to parent are part of the branch (that is a node of the branch graph). Thus, if user wants to have this commit in a different graph, then the deltas need to be regenerated and recommitted (then deleted from the wrong graph). As for the branch name, in Git it's just a label for the graph leaf. However, some SCMs maintain branch name for all constituing nodes in the branch graph.
- elsjaako 4y agoIf you are talking about the thing that git calls a branch, it's literally just a pointer to a commit. You can look it up manually. Here is a random repo I have on my PC: ~/p/s/sigrok-cli> cat .git/refs/heads/master 7bdc46d6fcdcfa00dd29ac102f3128aeb44a479c In principle all these objects are in the .git/objects folder. But the encoding is some binary thing for branches, and anyway it's often stored differently (I assume for space saving reasons). But git can explain what every object is. ~/p/s/sigrok-cli> git cat-file -p 7bdc46d6fcdcfa00dd29ac102f3128aeb44a479c tree fa02da4030e5791695b8a7a5400ee2c2cc88ee46 parent 09fc39da486b8618d65b66ca96a760478c3e89e2 author Uwe Hermann <...> 1454100673 +0100 committer Uwe Hermann <...> 1454100673 +0100 NEWS: Update for upcoming 0.6.0 release. ~/p/s/sigrok-cli> git cat-file -p fa02da4030e5791695b8a7a5400ee2c2cc88ee46 100644 blob d1d8ffca429d2a4697a56fd7dedbeee3fc6d577d .gitignore 100644 blob 28c1b20e6d7d146fbc6ad0270ff5b09cfd057b26 AUTHORS 100644 blob 94a9ed024d3859793618152ea559a168bbcbb5e2 COPYING 100644 blob 04c29abe3dc42c8ecb8ec1b71093437d8c382ebd HACKING 100644 blob c6d6c8a7cff1a5b7d940e0c040ad1d4f5337f646 Makefile.am ... etc The git software just updates the branch to create the illusion that it's not just a pointer to a commit. But really, it's literally a file with the sha1 hash of the commit.
- thefz 4y agoGit is just a tool, or better, a toolset for software development. Saying that it is too hard to me is a huge red flag. It means you do not want to spend the time, or the effort, to learn it. It's like a mechanic saying that a wrench is too complex.
- Alakbar 4y agoI think your analogy is a bit reductionist. The difference between git and a wrench is that the wrench presents almost all of its intended uses. I can quite confidently say that most people will understand it within a few minutes. Git is like CSS in the sense that for experienced users will sometimes forget the difficult learning process they went through, e.g. "oh use margin auto to centre the div" I've been there, finding git too hard and giving up, but I've came back to it and eventually got past that uncomfortable learning bump.
- amai 4y agoO shit git, I accidentally pushed sensitive data (password, private key, API access key,...) https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository https://docs.github.com/en/authentication/keeping-your-accou...