Live data from Hacker News

Learn the workings of Git, not just the commands (2015)

developer.ibm.com

21–30 of 98 posts

Re: Learn the workings of Git, not just the commands (2015)

#21
post #14
post #13

Earlier quoted context omitted.

quick: explain to me the difference between "git reset", "git revert" and "git restore", without looking up the docs.

But are these things a normal user would need to care about? I bet if you created a great git desktop app with outstanding UI it would still have a few corners 99% of users would never touch or understand.

> But are these things a normal user would need to care about?

... yes? I've used all three of those commands in the past, although I don't remember what they do. and I'm hardly a git expert.

Re: Learn the workings of Git, not just the commands (2015)

#23

"In this case, the conflicting result is left in the working directory for the user to fix and commit, or to abort the merge with git merge –abort." I've used git for many years, and I still zip the repo folder, before doing a large merge, since 'fix the commit' can be a large effort with conflicts. Quickly renaming the repo root folder, then unzipping the old version can be quicker/safer, if you are not a git ninja…

Quick tip: Git branches are cheap. Like super-cheap. IF you want to create a safe point just before doing a tricky merge, just spin off a new branch pointing at the current commit:

git branch blah_branch_backup

Later, if your merge gets completely messed up, you can do:

git merge --abort

git reset --hard blah_branch_backup

That final command will restore the current branch's HEAD to point to the same commit as blah_branch_backup.

This same pattern is useful for other dangerous commands, like rebases or filter-branch.

When you're done, just delete blah_branch_backup.

Re: Learn the workings of Git, not just the commands (2015)

#24
post #22

A mucher better explanation of git interals: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects It is surprisingly simple and efficient. I am starting to think this Linus guy knows what he is doing.

I still very much recommend the Peepcode Git Internals book.

https://github.com/pluralsight/git-internals-pdf/releases

Re: Learn the workings of Git, not just the commands (2015)

#25

"In this case, the conflicting result is left in the working directory for the user to fix and commit, or to abort the merge with git merge –abort." I've used git for many years, and I still zip the repo folder, before doing a large merge, since 'fix the commit' can be a large effort with conflicts. Quickly renaming the repo root folder, then unzipping the old version can be quicker/safer, if you are not a git ninja…

Quick tip: Git branches are cheap. Like super-cheap. IF you want to create a safe point just before doing a tricky merge, just spin off a new branch pointing at the current commit: git branch blah_branch_backup Later, if your merge gets completely messed up, you can do: git merge --abort git reset --hard blah_branch_backup That final command will restore the current branch's HEAD to point to the same commit as blah_b…

You can also use git-reflog to restore the branch back to the state it was before the merge. So instead of creating a temporary branch, you can inspect the reflog, find the entry before the merge commit and do git reset --hard HEAD@{X}.

Re: Learn the workings of Git, not just the commands (2015)

#26
post #14

Earlier quoted context omitted.

But are these things a normal user would need to care about? I bet if you created a great git desktop app with outstanding UI it would still have a few corners 99% of users would never touch or understand.

How to undo a change or revert to a previous version? That sounds like a pretty fundamental thing that a user would need to do, yes.

It is usually as easy as "git checkout ID".

If that doesn't work you probably have done something really bad to begin with.

Re: Learn the workings of Git, not just the commands (2015)

#27
post #5

Understanding what git is doing under the hood did more for my ability to use it effectively than it did for most tools. That said, this document in particular does not seem to be a very good way to get that understanding, it's a very "IBM documentation" way of presenting git. I wish I remembered what I read, because it's was a much easier read.

I found the Git section of "The Missing Semester of Your CS Education" to be helpful.

Re: Learn the workings of Git, not just the commands (2015)

#28
I like the attitude of "learn the principles of the simple building blocks behind it" as a good next step from a freshman that just memorized "add, commit & pull/push"

But most headache (and heartattack) inducing part of Git when I was a beginner was the "remote vs local repo" and additional complexities this concept introduced. Nothing more stressing for the new guy than making mistakes that screw up for others (mistakeful push, merge, mostly ) or if he think he did.

The article does a poor job (imo) regarding this. It skims on a 2 paragraph "Caveat" section how rebase(and later squeeze) can fuck local vs remote repo, but for most people I know, stress memories around this is what made them learn more about Git beyond than "branch & history keeping software & commands.

That and if you unfortunately end up in a project that uses subtree or submodules

Re: Learn the workings of Git, not just the commands (2015)

#29

The important thing to understand is that git is a blockchain

It goes a lot further than just being a blockchain. Git is a DAG through and through. But this might actually be the best way to make some people understand it. I was gobsmacked one day when a colleague came into work and they were really excited as they'd realised git is actually a blockchain. I was stunned as it seemed so obvious, but if they only just realised then how had we been working successfully with git for so long?

Re: Learn the workings of Git, not just the commands (2015)

#30

Earlier quoted context omitted.

"Zipping the folder" and keeping a copy of it is literally the sole purpose of a version control system. These kind of comments baffle me, quite honestly. But that is my fault, not yours. Could you tell me what you think git is for and why you use it?

Congrats never getting into a time consuming git mess, but I do sometimes. This is a very rare event. Recently I tried changing the committers email (each commit has a name and email attached) but that commit was already pushed into the repo, and I could not recover from the resulting mess. Even had to delete my github fork, and fork again. Happens about twice a year, while I used git commits many times every day.

You misunderstand. Do you think I was born understanding how git works? I've messed up at least as much as you, but I spent the time learning how it works rather than going nuclear and deleting the repository. I can't relate to how you think about git because it's been too long for me, that's why I asked if you could explain it from your point of view.
Post reply on HN