Undo a commit that is already pushed
A bad commit is on the shared branch. Others may have it.
The problem
A bad commit is on the shared branch. Others may have it.
How the practice repository looked before
## main
19fd99e Add line two 64396ec Add notes
The fix
[main 6a8c684] Revert "Add line two" Date: Fri Jan 9 10:00:00 2026 +0000 1 file changed, 1 deletion(-)
Check the result
6a8c684 Revert "Add line two" 19fd99e Add line two 64396ec Add notes
6a8c684 Revert "Add line two" notes.txt | 1 - 1 file changed, 1 deletion(-)
Why this works
git revert adds a new commit that does the opposite of the old one. History is not rewritten, so it is safe to push and safe for teammates.
If this is not quite your case
To revert several commits, list them or give a range. To revert a merge commit you must say which side to keep with -m 1. After the revert, push as usual: no force is needed, because history only grew. If the revert itself conflicts, fix the files, git add them and run git revert --continue.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.