Reset
In general, git reset is used to move branch tips around (likely to another commit)
resetis the opposite ofadd
If we pass a filename to git reset, then the staging area will be updated to match the given commit instead of the working directory (the branch pointer does not move).
- ex. if we have 3 files staged, we can remove one of them with
git reset HEAD index.js, makingindex.jsmatch the version found in HEAD. The working directory and current branch are left alone. The result is a staging area that matches the most recent commit and a working directory that contains the modifiedindex.jsfile.- Put another way, we are unstaging the file.
Soft
- moves the HEAD to the provided
<SHA>, while keeping working tree and staging area intact. - soft means the commit is canceled and moved before the
HEAD git reset --soft HEAD^- undo last commit
Mixed
- moves the HEAD to the provided
<SHA>, while keeping working tree intact.- Move the HEAD backward
<n>commits, but don’t change the working directory.
- Move the HEAD backward
- reset the staging area
git reset <file>is the opposite ofgit add <file>- ex. if we are on c3 and do
git reset c1, we will go back to c1, and the working directory and index will remain unchanged- This is the default type of reset
Hard
- moves the HEAD to the provided
<SHA>, keeping neither the working tree nor staging area intact.- Move the HEAD backward
<n>commits, and change the working directory to match
- Move the HEAD backward
- the only version of
resetthat actually results in a changed working directory file. - ex. if we are on c3 and do
git reset --HARD c1, we will go back to c1 (i.e. our head will point to c1) and c2 and c3 will be "destroyed", and working directory wiped.
Children