git-reset:tldr:8815b
The git reset
command is a powerful tool in Git that allows you to undo changes and move the head of your branch to a specific commit. It has different options and usages depending on the scenario you're dealing with.
Here are the three common forms of the command:
-
git reset --soft <commit>
: This form ofgit reset
allows you to move theHEAD
to a specific commit, keeping the changes made after that commit as uncommitted changes. It effectively "unstages" the changes. You can then modify or re-commit those changes as needed. -
git reset --mixed <commit>
orgit reset <commit>
: This is the default behavior if you don't specify any additional options. It also moves theHEAD
to a specific commit but discards the changes made after that commit. In this form,git reset
is essentially used to unstage the changes and reset the staging area to the specified commit. The changes are still present in the working directory, allowing you to modify or re-stage them. -
git reset --hard <commit>
: This form is the most powerful and potentially dangerous. It moves theHEAD
to a specific commit and completely discards all changes made after that commit, reverting your working directory and staging area to the state of that commit. Any uncommitted changes and staged files will be permanently lost.
It's important to note that when using git reset
to move the HEAD
to a previous commit, you shouldn't use it on a shared branch that others might have based their work on, as it can cause confusion and conflicts when they try to merge their changes with the updated branch.
In summary, git reset
is a versatile command that allows you to manage the state of your branch, undo commits, and unstage changes based on your needs. It's a powerful tool but should be used with caution, especially when using the --hard
option.