4 ms·
I think the biggest problem people have with git is that you can't and shouldn't want to change shared history, and yet git provides some tools that suggest tha
by mcv 10y ago
I think the biggest problem people have with git is that you can't and shouldn't want to change shared history, and yet git provides some tools that suggest that maybe you can.
It's better to accept history as it is, and fix the problem with reverts, cherry-picking and new commits. History won't be as pretty or clean, but it will reflect what actually happened, which is what history is, after all.
The biggest trick to understanding git is to learn to think in commits rather than file content. If one branch has a commit and the other branch doesn't, merging them will mean that the commit is there. If one branch has the commit while the other branch has the commit and a revert for that commit, merging will mean it will be reverted.
Same goes with pushing. If you reset locally to before a commit that you already shared, that commit returns on your next pull. If you revert it, it will stay reverted.
The most dangerous thing git can do, is rebasing. Rebase changes history. This is fine if it hasn't been shared yet (you commited a new change and try to push, but remote changes need to be pulled first, so rebasing is fine). Rebasing is not fine if the commit has already been shared, through a different branch or a different remote repository, for example. In that case, you need a merge.
As pretty as rebase can make your history, you should really only use it when you understand what it does. If you don't, stick with merge.
- tech2 10y ago> but it will reflect what actually happened, which is what history is, after all. Recorded history is not necessarily what actually happened though, often (or always, according to some) it's an interpretation. "History is written by the victors" - Walter Benjamin?
- l0b0 10y ago`git rebase -i` by default rebases only back to the first commit you haven't shared (at least that's how I interpret the actual behaviour). This is a great default - it's the simplest way to change history and at the same time powerful without being too dangerous.
- ZeroGravitas 10y agoAh, interesting. I'd noticed this behaviour but hadn't conciously thought about it. The docs say: All changes made by commits in the current branch but that are not in <upstream> are saved to a temporary area. This is the same set of commits that would be shown by git log <upstream>..HEAD
- mcv 10y agoIf they're not in upstream but they are in another branch, it's still dangerous.
- skissane 10y agoI think the ability to edit history is one of the great advantages of Git. I encourage people to use it rather than ignore it. Cleaner history makes life much easier for those who will try to understand what you did weeks or months or even years later (including your future self). Of course, you shouldn't (with rare exceptions) edit history you have already shared with others; but, I never found that concept, or the way git implements it, particularly hard to understand. (I will admit some of git's commands are hard to remember - I am always forgetting the difference between "git reset --hard" and "git reset --soft".)
- Ntrails 10y ago> If one branch has a commit and the other branch doesn't, merging them will mean that the commit is there. If one branch has the commit while the other branch has the commit and a revert for that commit, merging will mean it will be reverted. See, I fundamentally disagree that this is what I wanted. When I merge my thing with change x into head I expect to see my changes actually go in. Not to see commits retroactively added to head. The merge was the action, not some weird rewriting of historical order of events. > The biggest trick to understanding git is to learn to think in commits rather than file content. Ok, I'm starting to see what you meant. (I didn't understand this until the second part and my being confused as heck)
- falsedan 10y ago> I think the biggest problem people have with git is that you can't and shouldn't want to change shared history, and yet git provides some tools that suggest that maybe you can. Funny, I think the biggest problem is people who refuse to understand the caveats of rewriting shared history and spread FUD about it.