Thursday, January 30, 2025
HomeProgrammingHow to Cancel a Local git commit?

How to Cancel a Local git commit?

To cancel a local Git commit, you can use the git reset command. There are two common approaches:

  1. Soft reset (keep changes staged):
    bash
    git reset --soft HEAD~1

    This undoes the commit but keeps the changes staged, allowing you to modify or re-commit them.

  2. Mixed reset (keep changes in working directory):
    bash
    git reset --mixed HEAD~1

    This undoes the commit and un-stages the changes, but keeps them in your working directory.

For a hard reset (discard changes completely), use:

bash
git reset --hard HEAD~1

This will remove both the commit and changes.

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