16 ms·
Oh Shit, Git?
- ThrowawayR2 6y agoNeeds an entry for git submodules issues where the answer is to light the computer on fire and find a new profession.
- tarkin2 6y agoFew things give me such a wonderful sense of a achievement than removing a git submodule from a repo, however.
- tele_ski 6y agoAdding and updating submodules feels so straightforward but... removing yeah bring out the big guns, I can never get it done right and have to resort to searching
- BluSyn 6y agoThis please! Submodules are the only time I ever have real issues with git. I manually edit .gitmodules more than I care to admit, naturally this causes its own set of issues.
- dreamcompiler 6y agoI learned a long time ago never to invade Russia in winter and never to use git submodules. Git doesn't compose.
- anchpop 6y agoI think if git submodules were architectured differently, they could have been a really interesting solution for package management. In fact my last place of work uses a layer on top of submodules as part of their internal package manager. I think they could be really special but unfortunately are now sort of relegated to history.
- jayd16 6y agoActually, a lot of dependency managers are starting to accept git repos as dependency sources with pinned hashes as versions. Works out pretty well.
- ss3000 6y agoIn practice the biggest issue I've found with git+pinned hashes as dependencies is most public sources of remote git repositories allows the repository to be taken down by the author at any time, i.e. an author can turn a public github repo private or simply delete it at will. Whereas most public package registries generally don't allow removal of publicly published packages outside of special circumstances, so the references will be more durable.
- closeparen 6y agoI wish they didn't. Git clone is very slow relative to downloading a tarball. Glide/Dep would take tens of seconds to download what amounted to a few megabytes.
- mvn9 6y agoThat doesn't make sense. Winter is the best time to invade Russia because you have fresh supplies, you are prepared for winter and you have spring, summer and autumn to secure it. The mistake is to invade Russia in late summer because the campaign will be prolonged and you will have to secure Russia in winter, with your summer clothing, which is the problem. *edit: But don't forget about the nuclear bombs and the evilness of war itself. It's never a good idea to invade Russia.
- hnarn 6y ago> you have spring, summer and autumn to secure it. This is so historically ignorant it’s amazing.
- mvn9 6y agoCould you elaborate? As far as I know, Japan attacked in winter and won, everybody else lost in any conflict of which I am aware. [1] [1] https://en.wikipedia.org/wiki/Russo-Japanese_War https://en.wikipedia.org/wiki/Russo-Japanese_War
- hnarn 6y agoI’m not sure what you mean by “won”, the Japanese most certainly did not conquer Russia, which is the entire point of this old truth: that the geography and vastness of Russia makes it extremely difficult, if not impossible, to conquer. It’s a very different thing to attack Russia and have them cede territory to you, this has been done many times even by European countries.
- deleted 6y ago[deleted]
- CalChris 6y agoThe quote, usually known from the Princess Bride, is actually from Field Marshall Montgomery addressing the House of Lords: The next war on land will be very different from the last one, in that we shall have to fight it in a different way. Rule 1, on page 1 of the book of war, is: "Do not march on Moscow". Various people have tried it, Napoleon and Hitler, and it is no good. That is the first rule. I do not know whether your Lordships will know Rule 2 of war. It is: "Do not go fighting with your land armies in China". It is a vast country, with no clearly defined objectives. Montgomery didn't say except in Winter. He said don't do it all.
- jayd16 6y agoI started using them again and it seems fine. You're ok as long as you use it for things like external library projects and not splitting your project repo into smaller bites just for the sake of doing it.
- _asummers 6y agoRemoving them after adding to a project is still a 6-7 step process (unless this has changed and I missed it), which makes them feel clunky to use, to me.
- edflsafoiewq 6y agoWhat's wrong with git rm path/to/submodule?
- StavrosK 6y agoAFAIK that's recent.
- edflsafoiewq 6y agoIt seems to be from 2013: https://github.com/git/git/commit/95c16418f0375e2fc325f32c3d7578fba9cfd7ef https://github.com/git/git/commit/95c16418f0375e2fc325f32c3d...
- matheusmoreira 6y ago> splitting your project repo into smaller bites just for the sake of doing it That's exactly what lots of people want to do. Would be nice if it worked like the development mode of Python's packages: I can install a local development copy of the dependency somewhere, the main program will see the changes I make and therefore it's possible to develop both at the same time.
- maxnoe 6y agoYou can just work in the submodule. What am I missing here?
- cjfd 6y agoHmmmm.... I think the main problem with git submodules is that if you google 'git submodule' you don't find anything useful. When you somehow discover how they actually work they are... uhm... let us say... 'usable'... Maybe someone should write a tutorial about git submodules that is actually informative.
- tracer4201 6y agoThanks, that last entry gave me a good chuckle. I wasn’t aware of the -—no-edit flag when performing an amend. Learned something new.
- michaelmior 6y agoHuh. Neither was I. I've been using -C HEAD which has the same affect (reusing the commit from the branch head) but --no-edit makes it more obvious what's going on...sort of. It's still not clear what isn't being edited.
- grayhatter 6y agoWhat are the options for what could be the target? Or I guess in this case, what isn't the target.
- michaelmior 6y agoDo you mean the target of the editing? It could also be the commit author or committee perhaps. Maybe the message is the only logical choice, but for long flags, I think more explicit is still better.
- wffurr 6y agoA+ my go-to git reference. I don't work with git in my day job mostly, but when I do I end up here at least once a month.
- runawaybottle 6y agoLove this, definitely needs part 2 and 3 for rebasing and so forth.
- atum47 6y agobump for interest
- matanrubin 6y agoEspecially for handling branches that were rebased and force pushed. 90% of the times that I needed to help someone with git were due to a branch that was rebased and (force) pushed to the remote, and the person I was helping didn't know how to handle that and align his local copy with the remote.
- O_H_E 6y agoNot a rescue guide, but a very nice and animated hands-on tutorial: https://learngitbranching.js.org/ https://learngitbranching.js.org/
- ldiracdelta 6y agoBitkeeper was better. Larry McVoy is a hero.
- JakeStone 6y agoI was today days old when I learned about 'git reflog'. I may have to play with that sometime soon.
- Waterluvian 6y agoCorrect me if I’m wrong but these all seem to fix problems that exist in a local clone only. And that’s where none of my “oh shit” moments happen. All of my oh shit moments are two flavours: I have pushed to remote, or I have pushed to remote and force pushes are disallowed. I want a list of as graceful solutions as possible for those scenarios. And certainly they can be real-world solutions like “this cannot be undone in a desirable way so here’s an approach to handle the commit(s) necessary to fix the problem. This also brings up a question I didn’t realize I had: are people using git without frequently pushing to remote? I feel like having a remote backup of my work in progress is the killer feature. I can’t imagine doing any amount of work and not backing it up.
- bkanber 6y agoThere's a reason commit and push are two separate actions. That said, most people commit+push in the same keystroke. git revert is my best friend.
- Waterluvian 6y agoWhat is the reason? Like are people just not pushing changes to remote branches? Or is there some value in stuff to do in the small time between commit and push? Like are you checking your work before pushing?
- pirocks 6y agoIn the past I've done stuff like not pushing until the end of the day/coding session. Usually though I just end up committing and pushing immediately and then realizing I need to amend something and make a note to rebase later(I totally always do that rebase /s).
- dec0dedab0de 6y agoI try to keep my commits small, and I don't push each time because I have a Jenkins pipeline thats going to update a server for my branch and run unit tests and all that
- 6y ago
- ARandomerDude 6y agoGood tips, not a page I would use at work on account of the title. I get that SV is probably profanity-friendly, but a lot of us work in more reserved environments.
- woggy 6y agoA little bit off topic, but I hear a Pijul release is coming some time within the next week (its been a year since the last one). I've never really understood Git and always hoped for something else to come along, at least as an alternative.
- kyriakos 6y agoLooks interesting but the name may be blocking it from becoming more popular
- dang 6y agoIf curious see also 2019 https://news.ycombinator.com/item?id=19906972 https://news.ycombinator.com/item?id=19906972 2017 https://news.ycombinator.com/item?id=15951825 https://news.ycombinator.com/item?id=15951825 2016 https://news.ycombinator.com/item?id=12459755 https://news.ycombinator.com/item?id=12459755
- margaretdouglas 6y agoOh shit I accidentally force pushed my local master branch to origin.
- deleted 6y ago[deleted]
- Arnavion 6y agoWell, if you're already force-pushed it once, you might as well force-push the right commit (from reflog, if necessary) back to it again.
- margaretdouglas 6y agoOnly works if you've recently fetched origin, otherwise it'll be a challenge sorting out what the previous HEAD was.
- sio8ohPi 6y ago--force-with-lease is almost always the flag you ought to use instead. "--force-with-lease alone, without specifying the details, will protect all remote refs that are going to be updated by requiring their current value to be the same as the remote-tracking branch we have for them."
- atum47 6y agothat is some really useful shit right there. thanks for sharing
- grayhatter 6y agoIf y'all think git is hard, wait 'til you hear about computer algorithms! Git isn't hard, it might be complex, but how it works and how to use it is simple as far as applications and/or processes go. I find myself constantly trying to dispel the idea that git is too difficult to understand in depth. The problem has always come down to the missing attempt to understand the issue, over trying to ^c, ^v a solution. Seriously, if you think git is hard: don't ask for it to be easier, ask instead to be stronger. (Or in this case smarter, something you surprisingly have control over)
- geitir 6y agoI think it's more that you have to know git "reflog" instead of some easier non-cryptic command
- ramraj07 6y agoGit might not be hard, it might be easy, but for someone who has not spent enough time trying to understand it, it gives options to royally F up if you don't know what you're doing. So I make it a point to never use any command other than cherry-pick. Everything else I use GitHub desktop for. Its a simple ui that only lets you do the bare minimum of git actions thats less F up prone. Thats my personal story. The other problem I see is a large number of engineers who say git is not hard, it's very straightforward and they understand it very well, but actually they don't. And every once in a while they royally F up the entire repo and cause issues in deployment because of that. So git's main problem from my perspective is that it's an extremely advanced, unforgiving tool that gives a false sense of expertise to many mediocre programmers.
- grayhatter 6y ago> Git might not be hard, it might be easy, but for someone who has not spent enough time trying to understand it, it gives options to royally F up if you don't know what you're doing. You've just described nearly every tool, show enough carelessness with a hammer and you'll certainly fuck something up. > So I make it a point to never use any command other than cherry-pick. Everything else I use GitHub desktop for. Its a simple ui that only lets you do the bare minimum of git actions thats less F up prone. Yes, when you handicap yourself, limiting to a subset of available features. You'll usually have fewer ways to screw up. But I hope that's not advice you give out to others. That's exactly the mentality I'm trying to encourage people to avoid. "I don't understand it, so instead of trying to learn more about it, I'll just limit my self to a trivial subset of the actual options." That's not how you get good at anything. > Thats my personal story. The other problem I see is a large number of engineers who say git is not hard, it's very straightforward and they understand it very well, but actually they don't. And every once in a while they royally F up the entire repo and cause issues in deployment because of that. Other people making a mistake is pretty common. Sorry you've had to deal with it, I've been there myself. Fixing others mistakes is pretty annoying. It's expecially annoying when they pretend like they already know everything they need to about git; refusing to learn anything new. > So git's main problem from my perspective is that it's an extremely advanced, unforgiving tool that gives a false sense of expertise to many mediocre programmers. Again, it's not extremely advanced. MS Word has more features/options than git does. And I'd never call git unforgiving. In-fact git has been my best friend; I deleted a live directory with a bunch of code that I (foolishly) didn't have backed up anywhere. Including a good portion of the .git directory. Thankfully, git was very forgiving to me, and I was able to restore most of it from the objects that git keeps. But that's something I didn't know how to do before deleting my repo. It's something I had to go out and learn.
- aloknnikhil 6y ago> Git documentation has this chicken and egg problem where you can't search for how to get yourself out of a mess, unless you already know the name of the thing you need to know about in order to fix your problem. This is exactly why I have been running "git diff HEAD" instead of "git diff --staging" to diff my changes that have already been added to staging. I didn't even know that flag was a thing. I really wish there was some sort of an auto complete that could go from me describing the problem to the thing suggesting commands. Oh well, until then thanks for this!
- robbiemitchell 6y agoIn general the command line is like navigating a cave with a flashlight. I love the idea of some multi-line hinting system that shows you common paths.
- everybodyknows 6y agoNote that the two commands are not in general equivalent. Try `git add some-modified-file`, then change some line of the working file just "added". `git diff HEAD` will show the new change, whereas `git diff --staging` will not.
- AlexCoventry 6y agoPorcelains like magit are really great for discovering git's full capabilities.
- winrid 6y agoI'm almost done reading Pro Git. I thought there was a good chance it'd be useless, but it was actually useful even after using Git for six years.
- acidburnNSA 6y agoI think there's an comic book version of this for sale from the same people. https://gumroad.com/l/oh-shit-git https://gumroad.com/l/oh-shit-git
- deleted 6y ago[deleted]
- kuharich 6y agoPrior comments: https://news.ycombinator.com/item?id=12459755 https://news.ycombinator.com/item?id=12459755, https://news.ycombinator.com/item?id=15951825 https://news.ycombinator.com/item?id=15951825
- catchmeifyoucan 6y agoI’ve almost been exclusively using the GitHub Desktop client as my primary Git Tool and I’m much more comfortable with git now and helping people out. Merge conflicts were super scary, but with VS code markers, it’s a breeze. The desktop tool also makes sure to fetch origin first. If my commit is incorrect, I just use the “revert” button and it lets me fix things. There are a few things like renames and branch deletes that I use the shell for, but I’m happy and more confident in using git since the desktop tool is effective. One thing I hate is the pesky .DS_Store on Mac. No matter how many times I ignore it, it just wants to be a part of my commit.
- SeekingMeaning 6y ago> One thing I hate is the pesky .DS_Store on Mac. No matter how many times I ignore it, it just wants to be a part of my commit. Try a global gitignore: https://stackoverflow.com/questions/7335420/global-git-ignore https://stackoverflow.com/questions/7335420/global-git-ignor...
- dreamcompiler 6y ago.DS_Store is mostly a problem for me if I do my first commit without a .gitignore file, on a machine where I don't have a global .gitignore. In those cases you have to explicitly remove already-committed .DS_Store files from the repo before your new ignore settings will take effect.
- SebastianKra 6y agoSounds like you already committed it before adding it to the gitignore. Here's a fix: https://stackoverflow.com/questions/13541615/how-to-remove-files-that-are-listed-in-the-gitignore-but-still-on-the-repositor#13541721 https://stackoverflow.com/questions/13541615/how-to-remove-f... ...but this shouldn't be a problem with a good git client such as Fork (git-fork.com) or SourceTree. They show you the changed files and let you select which ones to commit. I would never commit anything without at least skimming the changes first.
- catchmeifyoucan 6y agoIn the GitHub client - if you point it to a folder and say “add repo from existing folder” it automatically makes an “init commit”. So you don’t get a chance. I’ll keep an eye on it next time.
- O_H_E 6y agoI LOVE how they have a non-swearing version at dangitgit.com :D
- jancsika 6y ago> git revert [saved hash] I see a future article forming: "The Power of Unix Pipes Except for The Zillions of Times Per Day Developers Awkwardly Drag a Mouse Over a Human Unreadable String Just to Make Trivial Git Commands Work"
- O_H_E 6y agolaughing in zsh completions. Not defending the git interface, but it is seriously bliss. See https://asciinema.org/a/LcarSXE90npusIczkIRdrzJLx https://asciinema.org/a/LcarSXE90npusIczkIRdrzJLx
- lma21 6y agowow! how do I do this for custom cli apps?
- O_H_E 6y agoIf you mean generate completion entries for you own tool, my answer will be 'I am not that kind of a guru ;D'. Go lookup creating zsh completions If you mean the interface with tabs, I am just using zsh-grml config (config file you download for those who don't care for a zsh plugin manger) (I believe very similar behavior is available in bash) Then, I just look up zsh completion for $TOOL.
- jeppesen-io 6y agoJust me, but git rebase -i is my go-to tool when I make a mistake
- harrispj 6y agoImho, just start using one of the desktop clients. I really like GitKraken but I've heard good things about tower too. Cannot emphasize how easy GitKraken has made my life when I eventually get into these scenarios.
- dskrvk 6y agoI prefer https://github.com/k88hudson/git-flight-rules https://github.com/k88hudson/git-flight-rules which is more complete and doesn’t use unnecessary swearing.