I would like to know how to delete a last pushed commit without affecting my local unstaged changes? This is the last commit id: ae04c55ce4b43c90c4bd8de9e4152b561b5055d6
Asked
Active
Viewed 610 times
-2
-
I think if I do reset --hard then my local uncommitted changes will also go – r121 Jul 04 '22 at 12:07
-
P.S. Google helps a lot solving this problem ;-) – YesThatIsMyName Jul 04 '22 at 12:12
-
I already did answered your question about `--hard` flag in the previous one you asked. I will share the same [link](https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard) once again, this time, please read it before posting new question. – kadewu Jul 04 '22 at 12:20
1 Answers
0
To revert remote changes, you will need to push force
(which I recommend to fully understand before proceeding)
Then steps in will be
- Remove locally:
git reset --hard HEAD~1
, - Then remove remotely
git push --force origin <branch>
Again, the force flag is dangerous, an alternative will be to use the revert
command to eliminate changes with an additional commit.

Gonzalo Matheu
- 8,984
- 5
- 35
- 58
-
-
In the question is part `without affecting my local unstaged changes` `git reset --hard HEAD~1` will remove unstaged changes. You need to use `git reset --soft` – kadewu Jul 04 '22 at 12:16