git.day/13 • See all at git.day
It's often the case that git-reset is used to reset changes in the working copy. The --hard option is frequently used to change the files to a previously committed state, such as discussed in Git of the day #6: git reset --hard ORIG_HEAD undoing a complex operation.
As an opposite to --hard, the --soft option keeps the working copy as is. This resets HEAD to a given commit without changing the files, and indeed stages the changes that would have been removed with --hard.
Since --soft keeps the changes staged, it can be thought of as undoing the commit, but keeping the add. That is, the usual flow of operations is
- make changes,
git add file,git commit
and therefore git reset --soft HEAD^, as HEAD^ is the parent commit of HEAD, undoes step 3 without undoing step 2. Therefore, the operations to undo each of the above steps are
git reset --hard HEAD^git reset --mixed HEAD^(equivalent to omitting--mixed, i.e.git reset HEAD^)git reset --soft HEAD^
This gives a simple equivalent to each command making it easy to undo these operations without unintentional loss of changes.
Leave a Reply