HomeToolsAbout

Reset

git reset is a command to fix uncommitted mistakes

  • unstages the index and leaves your working directory untouched.
# Unstage all files git reset . # Reset to previous commit git reset HEAD~1

identical to git reset HEAD, if you want to unstage the file, you can use rm --cached. you unstage the entire file from index, but you don't remove it from the working dir

git rm --cached added_file_to_unstage

Reset Types

git reset --hard commit_sha
  • --hard resets everything. Use this to undo merged. your current directory would be exactly as it would if you had been following that branch all along. the working directory and the index are changed to that commit.
git reset --soft commit_sha
  • --soft does not reset the working tree nor the index. It only moves the HEAD pointer. This leaves your current state with any changes different than the commit you are switching to in place in your directory, and “staged” for committing. If you make a commit locally but haven’t pushed the commit to the git server, you can reset to the previous commit, and recommit with a good commit message.
git reset --mixed commit_sha
  • --mixed resets the index, but not the working tree. so the changes are still there, but are unstaged and would need to be git added. we use this sometimes if we committed more than we meant to. we can back out the commit with git reset --mixed, add the things that we want to commit and just commit those
AboutContact