←back to thread

1062 points mixto | 2 comments | | HN request time: 1.134s | source
Show context
scrapcode ◴[] No.42942555[source]
I can't help but feel that Git has completely missed the forest through the trees that you can make a 30+ part guide explaining how to use it.
replies(6): >>42942641 #>>42942672 #>>42942768 #>>42943372 #>>42950299 #>>42954886 #
ajross ◴[] No.42942768[source]
My sense, bluntly, is that if people spent half the effort learning git that they do whining about it, no one would bother making a 30+ part guide just explaining stuff you could find in a man page.

Commits are snapshots of a tree. They have a list of ancestors (usually, but not always, just one). Tags are named pointers to a commit that don't change. Branches are named pointers to a commit that do change. The index is a tiny proto-commit still in progress that you "add" to before committing.

There. That's git. Want to know more? Don't read the guide, just google "how to I switch to a specific git commit without affecting my tree?", or "how do I commit only some of my changed files?", or "how to I copy this commit from another place into my current tree?".

The base abstractions are minimalist and easy. The things you want to do with them are elaborate and complicated. Learn the former, google the latter. Don't read guides.

replies(7): >>42942804 #>>42942870 #>>42943548 #>>42944155 #>>42944541 #>>42946116 #>>42946888 #
wruza ◴[] No.42944541[source]
This doesn’t work. Look:

Commits are sets of files. They form a tree. A branch is a named location in this tree. The index aka staging area is a pre-commit that has no message. Workdir is just workdir, it doesn’t go in the repo unless you stage it. HEAD is whereafter commit will put new changes.

Do I understand git? Seems like yes. Let’s run a quiz then! Q? A.

How to make a branch? Git branch -a? Git checkout -b --new? Idk.

How to switch to a branch? Git switch <name>, but not sure what happens to a non-clean workdir. Better make a copy, probably. Also make sure the branch was fetched, or you may create a local branch with the same name.

How to revert a file in a workdir to HEAD? Oh, I know that, git restore <path>! Earlier it was something git reset -hard, but dangerous wrt workdir if you miss a filename, so you just download it from git{hub,lab} and replace it in a workdir.

How to revert a file to what was staged? No idea.

How to return to a few commits back? Hmmm… git checkout <hash>, but then HEAD gets detached, I guess. So you can’t just commit further, you have to… idfk, honestly. Probably move main branch “pointer” to there, no idea how.

If you have b:main with some file and b:br1 with it, and b:br2 with it, and git doesn’t store patches, only files, then when you change b:main/file, then change and merge+resolve b:br1/file, then merge that into b:br2 to make it up-to-date, will these changes, when merged back to already changed b:main become conflicted? Iow, where does git keep track of 3-way diff base for back-and-forth reactualization merges? How does rebase know that? Does it? I have no idea. Better make a copy and /usr/bin/diff [—ignore-pattern] the trees afterwards to make sure the changes were correct.

As demonstrated, knowing the base abstractions doesn’t make you know how to do things in git.

I don’t even disagree, just wanted to say fuck git, I guess. Read guides or not, google or reason, you’re screwed either way.

replies(3): >>42946246 #>>42947164 #>>42948715 #
1. nextlevelwizard ◴[] No.42948715[source]
Knowing how to make a branch is very basics of using git. If you don’t know how to do it (git checkout -b, btw) you are just outing yourself as someone who doesn’t use git or your just push to master i.e. you are only working on solo projects.

You can switch branch also with ‘git checkout’ and you just ‘git stash’ your changes.

‘git reset’ is fine to reset files, but again if you just want to ”clean” repo you can stash.

You can reset staged files again with ‘git reset’

Mo idea why you would want to checkout a random commit and the start committing from that, but you can also just ‘git reset --hard HEAD~x’ where ‘x’ is number of commits you want to go back. Hard is optional, but I assume that is what you want based on your comment.

Depends on the change. If you change different lines there will be no conflicts.

This is all basic stuff you should know if you are developing code with other people

replies(1): >>42950322 #
2. wruza ◴[] No.42950322[source]
Threaded merges are easy to screw up, that's why git invented that "rebase" crutch, both be-cause and the-cause it doesn't know which changes are in revision, only the file contents. Not sure how one can look at it and not see (or meet) the problem. "If you change different lines there will be no conflicts." Oh really, I guess I have had no have issues with merging in long branches then, good to know it was fine. You can merge back and forth and it just works. No one itt has merge anxiety, you just do it and it's all fine, and if there are conflicts, it's only for the same lines. Would be laughable if a thing like git had a huge engineering gap here, good thing it doesn't. /s

You can reset staged files again with ‘git reset’

To "revert a file to what was staged" you have to "git checkout" again, it seems, not "reset".

This is all basic stuff you should know if you are developing code with other people

Yeah. It seems that it is basic, until you try using it for something that is not quick one-shot patching of "append-only" code.