A commit is not a point of no return. GitHub Desktop lets you rebuild a local commit with Undo or safely reverse a published commit with Revert.
First question: was the commit pushed?
- No, it is still local โ use Undo.
- Yes, it is already on GitHub โ use Revert.
Undo: rebuild a local commit
Undo removes the latest local commit from History but keeps every file change. The files return to Changes so you can review, improve, and commit them again.
Method 1: from Changes
- Open Changes.
- Find the latest local commit at the bottom of the sidebar.
- Click Undo.
- Confirm the files returned to Changes.
Method 2: from History
Some GitHub Desktop versions expose Undo in the context menu of the latest unpushed commit.
- Open History.
- Right-click the latest local commit.
- Select Undo commit if available.
- Return to Changes and inspect the files.
Undo is not Discard changes. Undo keeps edits; Discard changes removes uncommitted edits.
Revert: reverse a published commit
If a commit is already on GitHub, do not rewrite shared history. Revert creates a new commit with the opposite changes.
- Open History.
- Right-click the published commit.
- Select Revert Changes in Commit.
- Open the new Revert commit and read its reverse diff.
- Click Push origin.
The original commit remains visible. The new commit records its safe correction.
Undo versus Revert
| Situation | Tool | Result |
|---|---|---|
| Latest commit is local | Undo | Commit is unpacked; edits return to Changes |
| Commit is published | Revert | A new reverse commit is created |
| Remove uncommitted edits | Discard changes | Edits are deleted โ use carefully |
Revert does not remove secrets
If a password, token, private key, or API key was committed, Revert does not make it safe. The original value remains in Git history.
- Treat the secret as exposed.
- Revoke or rotate it immediately.
- Remove it from the current project version.
- Ask a responsible developer or mentor to help clean Git history.
- Never publish a real secret again to test the fix.
Checklist
- I checked whether the commit was pushed.
- I chose Undo for a local commit.
- I chose Revert for a published commit.
- I reviewed the diff before and after.
- I will not rely on Revert to protect a leaked secret.
๐ฌ Comments (0)
No comments yet
Be the first to share your opinion about this article!