3 ms·
`git reset --hard` resets your worktree to the HEAD state. `git checkout -- <file>` checks out the HEAD version of a given file.
by johnmaguire 5y ago
`git reset --hard` resets your worktree to the HEAD state.
`git checkout -- <file>` checks out the HEAD version of a given file.
- infogulch 5y agoYes, but you can also word it in two other ways that make the redundancy more apparent at the cost of a tiny bit of inaccuracy: A: `git reset --hard` checks out the HEAD version of your worktree. `git checkout -- <file>` checks out the HEAD version of a given file. B: `git reset --hard` resets your worktree to the HEAD state. `git checkout -- <file>` resets a file to the HEAD state. I don't think a newbie could even grok the difference between these three descriptions.
- gpanders 5y agogit reset --hard does not only modify the work tree though, it also updates where your current branch points to. In fact, that is the main purpose of ‘git reset’, the fact that it modified your work tree at all is only because of the ‘--hard’ flag. So it’s not correct to say that “reset --hard and checkout do basically the same thing”.
- aidenn0 5y agogit reset --hard HEAD Does in fact only modify the work tree, since updating the current branch to HEAD is a nop.
- johnmaguire 5y agoYou could word it that way, but it's not actually correct. Check the man pages to see why. (Or read the other commenter's note which gives a brief explanation.) > I don't think a newbie could even grok the difference between these three descriptions. This part is definitely true - Git offers only a very light abstraction on top of its data structures.