Live data from Hacker News

How to undo almost anything with Git (2015)

github.blog

61–70 of 84 posts

Re: How to undo almost anything with Git (2015)

#62
post #9

git-extras has a tool called `git undo`. It's just a fancy wrapper around `git reset --soft HEAD` though.

Well you never know what these wrappers and aliases do, and ultimately need to understand what goes on under the hood.

Intellij has a "shelve" command, I decided to stick with "git stash". Magit has the "i", that does "ignore" but also cleans up already committed files, something like "git rm -r --cached ."

Re: How to undo almost anything with Git (2015)

#63
post #48

Also worth noting: you can abort and undo many kinds of in-progress operations with “git —abort”. Works for merge, rebase, and a few other things, and can seriously save your bacon when you do a “git merge ” and are suddenly confronted with a bazillion merge conflicts. Also, if you’re in a panic because something went screwy, check “git status” and read every line carefully. status tells you a lot more than you might…

> check “git status” and read every line carefully. Seconded, but I'd go even further. Run and read git status before and after running any git command until you get comfortable enough with git to where you can predict the output without running it. Additionally you can go get git prompt[1] installed so you always know your git status at a glance. Saves a lot of typing in any case. As a last suggestion I'd say go rea…

I totally second reading the book front to back. It is not that long and fairly well written, and can save so much time and frustration in the long run. Giving the link is the first thing I do when helping someone with git.

Unfortunately so many people put that aside and never read it, and then come back to me a few weeks later because they messed everything up again, and still do not understand what I mean with "index".

Git is very powerful but a bit awkward, so I consider knowing the underlying concepts necessary to use it properly.

Re: How to undo almost anything with Git (2015)

#64
post #19

For several months now I've been wondering how to get rid of a 700 MB data file that was accidentally committed to our shared git repo. Now everyone has it, and a clean pull takes forever. Appreciate any thoughts.

Like others comment it's possible to scrub it from the repo entirely but this will change every commit hash (I'm guessing back to the commit where the file first appeared). It's probably something you need to coordinate carefully among all the teams. Have no open branches, scrub it, force push that then people can resume work.

Re: How to undo almost anything with Git (2015)

#65

Also worth noting: you can abort and undo many kinds of in-progress operations with “git —abort”. Works for merge, rebase, and a few other things, and can seriously save your bacon when you do a “git merge ” and are suddenly confronted with a bazillion merge conflicts. Also, if you’re in a panic because something went screwy, check “git status” and read every line carefully. status tells you a lot more than you might…

You can also use git-retain-history with reflog to sidestep unexpected git operations.

https://git-man-page-generator.lokaltog.net/#4b16e11f044dd60...

Re: How to undo almost anything with Git (2015)

#66
post #57

Earlier quoted context omitted.

When I used to use NetBeans the main feature I loved was the history feature. Basically every save to every file was stored and diffable in a kind of self contained repo. I've missed this feature in every other editor since.

IntelliJ IDEA has that feature (local history)

Can confirm.

Re: How to undo almost anything with Git (2015)

#67

Earlier quoted context omitted.

If you have to use the command line, those "gosh darn it git" sites have some good recipes. Because if the problem is "I accidentally committed to the wrong branch!" who is going to remember all this off the top of their head: # undo the last commit, but leave the changes available git reset HEAD~ --soft git stash # move to the correct branch git checkout name-of-the-correct-branch git stash pop git add . # or add in…

I know you're trying to sell your SyntEvo(R) SmartGit(TM), but the last thing I'd want while already trying to recover from a mistake is having a third party tool do some opaque magic on the repo, in the same way that I wouldn't just copy-paste a recipe without understanding how it works. OTOH if a common operation can be performed reliably I'd much rather it be upstreamed.

I'm also a non-shill advocating SmartGit at any opportunity. Is it so incomprehensible for FOSS users that there are commercial products that are so great that they have a dedicated fan base s opposed to half baked open source crap?

Re: How to undo almost anything with Git (2015)

#68

Earlier quoted context omitted.

If you have to use the command line, those "gosh darn it git" sites have some good recipes. Because if the problem is "I accidentally committed to the wrong branch!" who is going to remember all this off the top of their head: # undo the last commit, but leave the changes available git reset HEAD~ --soft git stash # move to the correct branch git checkout name-of-the-correct-branch git stash pop git add . # or add in…

> It works in conjunction with the command line Do you know of git GUIs that explicitly maintain a bijection between the GUI and the underlying command history? It'd be cool to use the GUI and see the command history, or use the CLI and see updates in the GUI.

> use the CLI and see updates in the GUI

Which GUI tool does not?

Re: How to undo almost anything with Git (2015)

#69
post #18

Earlier quoted context omitted.

I'm not that poster, but Mercurial is just as powerful and much easier to use.

That's what everyone says, but for me, coming from a rebase heavy git workflow, I've found Mercurial far more difficult to learn. For example, with Mercurial, there's at least four different ways to do a rebase-ish thing: transplant, graft, rebase, and rebase (w/ evolve enabled). It's not obvious which a newbie should pick (rebase+evolve... I think?). Likewise, Mercurial has purge and strip which both delete commits…

For example, with Mercurial, there's at least four different ways to do a rebase-ish thing: transplant, graft, rebase, and rebase (w/ evolve enabled). It's not obvious which a newbie should pick (rebase+evolve... I think?).

You're cherrypicking--no pun intended.

By default, Mercurial doesn't do any of these operations; you have to activate extensions.

If I were a newbie coming from Git and I wanted a similar workflow using Mercurial, I would probably start with rebase.

But these days, the Evolve extension is the way to go--using it is a lot easier than anything I've seen or experienced using Git: https://www.mercurial-scm.org/doc/evolution/user-guide.html.

I find it kinda ironic when in this message thread, people are praising a chart like this--http://justinhileman.info/article/git-pretty/. It feels like the DVCS version of Helsinki Syndrome…

By design, Mercurial makes it much harder to shoot yourself in the foot.

In contrast, there's an entire cottage industry (https://ohshitgit.com and the like) to help when you--inevitably--get into a bad situation with Git.

Post reply on HN