3 ms·
git-reset - Reset current HEAD to the specified state git-checkout - Switch branches or restore working tree files reset works primarily to modify HEAD, and
by wereHamster 5y ago
git-reset - Reset current HEAD to the specified state
git-checkout - Switch branches or restore working tree files
reset works primarily to modify HEAD, and when you include `--hard` it's like saying: oh and btw also update the working tree.
checkout works primarily (in the case of checkout <pathspec>) to copy file from somewhere (commit, index) into the working tree. You can use checkout to mimic a hard reset: `git reset --hard` is pretty much equivalent to `git checkout HEAD .`
- ajkjk 5y agoI understand how it works, but I still think it's dumb.
- wereHamster 5y agoIs it perhaps because most people are taught about `reset --hard` early on? If all they knew was `checkout` there wouldn't be any confusion. Nobody really needs to know about `reset --hard`, the same effect can be achieved with a normal reset and a checkout, it's a two step process anyway, regardless of how you do it. Using reset+checkout is not the quickest but gets the job done. Power users can create themselves a shell alias, or write themselves a small shell script, or learn about one of the thousands commandline switches that does just what they need.