Monday, January 20, 2025
HomeTechHow to Undo the Last Commit on Github?

How to Undo the Last Commit on Github?

To undo the last commit on GitHub, use the following steps:

  1. Undo Locally:
    • Run git reset --soft HEAD~1 to undo the commit while keeping changes staged, or
    • Use git reset --mixed HEAD~1 to unstage changes but keep them in your working directory.
  2. Push Changes to GitHub:
    • For a shared repository, use git push --force to overwrite the commit history.
See also  Functions of Operating System

⚠️ Caution: Avoid --force in shared repositories without team agreement to prevent overwriting others’ work.

For a safer alternative, use git revert <commit_hash> to create a new commit that undoes the previous one.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x