I\'m looking to split a commit up and not sure which reset option to use.
I was looking at the page In plain English, what does "git reset" do?, but I real
mkarasek's Answer is great, in simple terms we can say...
git reset --soft
: set the HEAD
to the intended commit but keep your changes staged from last commitsgit reset --mixed
: it's same as git reset --soft
but the only difference is it un stage your changes from last commitsgit reset --hard
: set your HEAD
on the commit you specify and reset all your changes from last commits including un committed changes. Here is a basic explanation for TortoiseGit users:
git reset --soft
and --mixed
leave your files untouched.
git reset --hard
actually change your files to match the commit you reset to.
In TortoiseGit, The concept of the index is very hidden by the GUI. When you modify a file, you don't have to run git add
to add the change to the staging area/index. When simply dealing with modifications to existing files that are not changing file names, git reset --soft
and --mixed
are the same! You will only notice a difference if you added new files or renamed files. In this case, if you run git reset --mixed, you will have to re-add your file(s) from the Not Versioned Files list.
You don't have to force yourself to remember differences between them. Think of how you actually made a commit.
Make some changes.
git add .
git commit -m "I did Something"
Soft, Mixed and Hard is the way enabling you to give up the operations you did from 3 to 1.
git commit
.git add .
All the other answers are great, but I find it best to understand them by breaking down files into three categories: unstaged
, staged
, commit
:
--hard
should be easy to understand, it restores everything--mixed
(default) :
unstaged
files: don't changestaged
files: move to unstaged
commit
files: move to unstaged
--soft
:
unstaged
files: don't changestaged
files: dont' changecommit
files: move to staged
In summary:
--soft
option will move everything (except unstaged
files) into staging area
--mixed
option will move everything into unstaged area
--soft
: Tells Git to reset HEAD to another commit, so index and the working directory will not be altered in any way. All of the files changed between the original HEAD and the commit will be staged.
--mixed
: Just like the soft, this will reset HEAD to another commit. It will also reset the index to match it while working directory will not be touched. All the changes will stay in the working directory and appear as modified, but not staged.
--hard
: This resets everything - it resets HEAD back to another commit, resets the index to match it, and resets the working directory to match it as well.
The main difference between --mixed
and --soft
is whether or not your index is also modified. Check more about this here.
Before going into these three option one must understand 3 things.
1) History/HEAD
2) Stage/index
3) Working directory
reset --soft : History changed, HEAD changed, Working directory is not changed.
reset --mixed : History changed, HEAD changed, Working directory changed with unstaged data.
reset --hard : History changed, HEAD changed, Working directory is changed with lost data.
It is always safe to go with Git --soft. One should use other option in complex requirement.