4 ms·
Explain detached head like i’m 5 years old.
by lixtra 8y ago
Explain detached head like i’m 5 years old.
- XCabbage 8y agoWhy should he have to? It's irrelevant to the point he's making, since a tool being conceptually difficult is not the same thing as it having footguns.
- masklinn 8y ago> a tool being conceptually difficult is not the same thing as it having footguns. But the tool is not conceptually difficult. All the difficulty of git is in the trap its "UI" creates for no reason. The concepts are easy. I taught Darcs to a frontend/flash developer 15 years ago, and it's not because I'm a great teacher.
- xyzzy_plugh 8y agoDetached HEAD isn't complicated. It simply means there is nothing tracking the current line of work beyond the commit shas themselves. No branch is updated when you make commits. Conversely, attached HEAD means a branch is being updated whenever you make a commit, e.g. when you make commits on your local master.
- iainmerrick 8y agoBut why would I get into that state, and how do I get out without losing my work? Neither of those is obvious.
- tome 8y ago> how do I get out without losing my work? When you move out of detached head state by checking out another branch Git tells you how to save your work to a branch.
- iainmerrick 8y agoIt could usefully say that when you do a “git status” when you’re in a detached state, instead of just saying “detached HEAD” and expecting you to figure it out (or google for it). It could very usefully try harder to avoid getting into that state in the first place.
- tome 8y ago> It could usefully say that when you do a “git status” when you’re in a detached state That's a great idea and it really confuses me why they don't add obviously useful things to the interface.
- annabellish 8y ago>It could very usefully try harder to avoid getting into that state in the first place. Am I missing something here? How do you get into a detached HEAD state without explicitly taking an obviously weird action, like finding and checkout out a commit hash instead of a branch, and why would it make sense for git to not be in a detached HEAD state should you do that?
- jamescostian 8y agoImagine someone does task X but they do it very poorly and in master. You want to get rid of their last few commits (without a force push). Most people don't think about doing a hard reset to the last good commit, and then soft resetting to HEAD~. Instead, they just "git checkout $LAST_GOOD_COMMIT". And afterwards they may even continue by working with a detached HEAD
- WorldMaker 8y agoRebase has several cases that will drop you into a detached HEAD. Rebase has gotten better at warning you when it is happening, and much better at telling you what your next steps are in that situation (such as git rebase abort), at least, but it still does it. Several times that I've helped junior developer out of a detached HEAD state, when I asked what they thought they were doing before it happened, the answer was "I was just doing my normal rebase before..."
- lixtra 8y agoOh, I see. I created this great patch and commited it. Then I wanted to push it, but it reported some strange error. I checked out master but now my commit is no longer there. HELP! Can I somehow push my changes to you so you can fix it? Ah let's intuitively try: git log --graph --decorate $(git rev-list -g --all) For comparisson: - mercurial would show your commit all the time, no matter what currently is checked out. - Only when you push, you have to force it, to create a new head in the remote repository because most workflows expect you to merge heads locally.
- seba_dos1 8y agoAll I get from this comment is that "git reflog" should be one of the first things taught about git :P
- mikestew 8y agoMaybe five year olds shouldn't be mucking with your source code. Detached is just that: you can party on it all you want, but it's not going to go anywhere when you commit unless you go out of your way.
- tome 8y agoIf you're in detached head then `checkout -b the_detached_head_i_just_had` and the fact that you were in detached head becomes irrelevant.
- chrisseaton 8y agoI get that could be confusing, but there's no 'gun' there, is there? You may have to move your commit, but nothing been damaged?
- lixtra 8y agoTime wasted is equivalent to damage. Every digital damage can be undone by wasting enough time.