I need to revert local changes for deployments. (I'd used svn revert
for this in old skool SVN days.)
And im using git reset --hard HEAD
for this. (Also git fetch
and git merge origin/$branch --no-ff
for syncronizing with upstream branch.)
But some articles points git checkout -f
for reverting changes.
What's key differences between this commands. Which way is the recommended?
The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on). So what is the “–hard” option used for? The “–hard” option is used in order to reset the files of the index (or the staging area) and of the working directory.
Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.
The two of them have the exact same effect. I recommend you to choose the solution you're the more comfortable with.
But if in this particular case the effect is the same, with different values it would be completely different. Basically (there is more, see linked topics) with a reset you move the current branch and the HEAD to a specific commit but with a checkout, you only move the HEAD . For more details see below.
Resources:
On the same topic:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With