Live data from Hacker News

How to undo almost anything with Git (2015)

github.blog

41–50 of 84 posts

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

#41
post #36

Earlier quoted context omitted.

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…

You surely don't know much about Mercurial. "purge" has NOTHING to do with commits. "purge" only removes file not tracked by Mercurial. "graft" replaced "transplant". "graft" copies commits while "rebase" moves commits. These commands all have very clear purposes, unlike those in Git. It's just that you haven't really bothered to spend a few minutes on learning them.

[deleted]

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

#42
post #40
post #36

Earlier quoted context omitted.

You surely don't know much about Mercurial. "purge" has NOTHING to do with commits. "purge" only removes file not tracked by Mercurial. "graft" replaced "transplant". "graft" copies commits while "rebase" moves commits. These commands all have very clear purposes, unlike those in Git. It's just that you haven't really bothered to spend a few minutes on learning them.

purge is a third-party extension; it removes untracked files as you wrote. But ~purge~ prune is also a command of the evolve extension, that is conceptually similar to strip, as GP wrote.

evolve doesn't have a purge command. It has a prune command.

purge is not a third party extension. It is distributed along with Mercurial.

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

#43
post #42
post #40

Earlier quoted context omitted.

purge is a third-party extension; it removes untracked files as you wrote. But ~purge~ prune is also a command of the evolve extension, that is conceptually similar to strip, as GP wrote.

evolve doesn't have a purge command. It has a prune command. purge is not a third party extension. It is distributed along with Mercurial.

You are correct, thanks.

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

#44
post #32

The thing that made git click for me was to understand the data structures that make git work. There's beauty and elegance in the implementation details of git. You can do and undo with confidence once you can translate the changes you want to make to git object transformations. To get an overview of the concepts behind git I recommend this article by one of the GitHub founders: http://tom.preston-werner.com/2009/05/…

Here also my 'git from scratch' TODO for the new year list : https://wyag.thb.lt/

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

#45

Earlier quoted context omitted.

Git shouldn't take months to master if you can understand it conceptually rather than by use-cases. If instead of trying to learn commands to affect the working directory, staged files, or history, you learn how git organizes historical tree of commit hashes, then base what each operation does, it becomes much clearer. It's similar to trying to learn strings of shell pipe commands to get things done rather than reali…

git’s problem to newcomers - even people without any prior experience with diff-paradigm systems like SVN and TFS - is the idea of a commit representing a snapshot of a file system is difficult to comprehend because it feels so crazy and impractical (especially as CS101 makes a huge deal about computational complexity). The fact that git internally is actually quite efficient is buried in heavy articles about git’s p…

IMHO, the main idea of git is immutability. See the following comparison of git and synergy in a migration study. https://github.com/24eme/eurocontrol_synergy2git/blob/master... The git description is far shorter, but also more complete.

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

#46
post #27

I'm actually somewhat surprised that this wasn't mentioned in the comments yet: https://ohshitgit.com/ Which is a page that covers common mistakes using git and quick ways to fix your mistakes. I've found myself making a mistake mentioned on this page with regularity and always refer to the site to help myself fix it quickly. (It looks like they have a swearing-safe version now at https://dangitgit.com/ )

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.

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

#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 read git-scm.com[2]. It has the excellently written man pages for looking up what a command does and which flags it takes. It also has an amazingly written free ebook explaining git top-to-bottom. After reading that you'll be a git wizard compared to your peers.

[1] https://github.com/git/git/blob/master/contrib/completion/gi... [2] https://git-scm.com/

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

#49

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.

Git-fork does this.

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

#50

Earlier quoted context omitted.

Git will even warn you if the hash prefix you provide is ambiguous! I had a collision the other day on a mediums-sized when using a 6 character hash and was surprised. Git let me know and told me which objects collided.

Wow, that's super unlikely. How many commits did the repo have? According to [1] using 3 letters you'd need at least 72 commits to have at least 50% chance to observe a clash. Using 6 letters you'd need at least 3977 commits, lol. [1] https://en.wikipedia.org/wiki/Birthday_problem#The_generaliz...

How is that unlikely? 4k commits is nothing. Any project with a dozen developers is going to reach that easily.
Post reply on HN