I just did a commit and realized I need to undo the commit without deleting any changes....how would I do that? I have tried git reset --soft
and that did nothing, no errors nothing, when I enter that command, literally nothing happens. What am I doing wrong?
Asked
Active
Viewed 751 times
0

Michele Dorigatti
- 811
- 1
- 9
- 17

user979331
- 11,039
- 73
- 223
- 418
2 Answers
1
git reset --soft
implies HEAD
, but you want to go back to the commit before HEAD
, thus :
git reset --soft HEAD^

Romain Valeri
- 19,645
- 3
- 36
- 61
0
Try this:
git reset --soft HEAD~1
The advantage of this way is you can reset softly for n
latest commits, just let the command know expected number of commits to reset softly.
For example, to reset softly last two commits:
git reset --soft HEAD~2
You might also want to learn about various modes of reset.

Shridhar R Kulkarni
- 6,653
- 3
- 37
- 57
-
by doing that they are now unstaged changes....what would happen if i unstaged them? – user979331 Jan 27 '20 at 18:51
-
they are already unstaged you are saying so why unstage again? – Shridhar R Kulkarni Jan 27 '20 at 18:52
-
Just re-stage them with `git add .`, but if you didn't want to unstage them, you could have used `--mixed` (implied) instead of `--soft`, so `git reset HEAD^` – Romain Valeri Jan 27 '20 at 18:52