So I've been working on this PR and it turns out that I need to revert a certain commit/push, note that I created multiple commits and pushes after that commit but I want everything to remain the same and only that commit to revert back, is that possible and how?
Asked
Active
Viewed 5,291 times
2 Answers
4
you can use
git revert <commitID>
This effectively create a new commit that reverse the previous commit.
Remember to commit/push after that.

Chan Jun Cheng
- 41
- 2
0
to see the history of commit and their hash value
git log
to undo a commit (soft reset)
git reset hash-value
if you want to erase the file and other changes after that commit then do a hard reset.
once you undo your commit you can push your changes to your Github!
git reset --hard hash-value

SwissCodeMen
- 4,222
- 8
- 24
- 34

Jatin Mehrotra
- 9,286
- 4
- 28
- 67
-
`once you undo your commit you can push your changes to your Github!` - OR not :) because the working copy would be behind the remote, so you'd need to either pull (which would recreate the removed commit) or force push (don't do this without knowing what you're doing). In the absence of any reason to act differently, a commit should always be undone via `revert`. – AD7six Feb 28 '21 at 17:01
-
point understood thanks :) – Jatin Mehrotra Feb 28 '21 at 17:04
-
please edit it as you like :) @AD7six – Jatin Mehrotra Feb 28 '21 at 17:16
-
I think this question has been answered enough times already :) – AD7six Mar 02 '21 at 09:17