Z
Z
zlodiak2018-02-19 23:27:36
git
zlodiak, 2018-02-19 23:27:36

What is the difference between git reset and git reset --soft?

I have a master branch with several commits:

* 1f52e4c 2018-02-20 | w3 (HEAD -> master) [zlodiak]
* 19299b6 2018-02-20 | w2 [zlodiak]
* ec499c2 2018-02-20 | w1 [zlodiak]
* fcbc61d 2018-02-20 | q1 [zlodiak]
* aae9725 2018-02-19 | cherry -1 [zlodiak]
*   5e5f31e 2018-02-19 | f [zlodiak]
|\  
| * 84611db 2018-02-19 | 5 [zlodiak]
| * 175f012 2018-02-19 | 2 [zlodiak]
* | 9f8fb98 2018-02-19 | 6 [zlodiak]
* | f25a332 2018-02-19 | 3 [zlodiak]
|/  
* 408d717 2018-02-19 | 1 [zlodiak]
* 710b3ba 2018-02-19 | 0 [zlodiak]

Let's say I wanted to rollback a few commits back and continue the story again from this commit. I do like this:
[email protected] /var/www/html/misc/tag $ git reset ec499c2
Unstaged changes after reset:
M	index.html
[email protected] /var/www/html/misc/tag $ git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short --all
* ec499c2 2018-02-20 | w1 (HEAD -> master) [zlodiak]
* fcbc61d 2018-02-20 | q1 [zlodiak]
* aae9725 2018-02-19 | cherry -1 [zlodiak]
*   5e5f31e 2018-02-19 | f [zlodiak]
|\  
| * 84611db 2018-02-19 | 5 [zlodiak]
| * 175f012 2018-02-19 | 2 [zlodiak]
* | 9f8fb98 2018-02-19 | 6 [zlodiak]
* | f25a332 2018-02-19 | 3 [zlodiak]
|/  
* 408d717 2018-02-19 | 1 [zlodiak]
* 710b3ba 2018-02-19 | 0 [zlodiak]

As a result, several commits were removed, and the working directory did not change. What happened suits me.
BUT I don't understand how the command I used (git reset ec499c2) is different from the command git reset --soft ec499c2. In my opinion these commands do the same thing. Namely, they roll back the history of commits and do not change the state of the working directory.
Please explain the difference.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-02-19
@zlodiak

--soft resets the commit as if a git add was done on the files
--mixed resets the commit as if there was no git add on those files, that's the default.
--hard resets the commit and removes the changes. But, a commit is available by its hash unless it's removed by gc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question