how to undo commit

Hi I want to undo my last commit. What I did is I made some changes to file then I commit them but I have not push them to main repo yet. After git commit -m “comment” command I ran git status and I got this message

Your branch is ahead of 'origin/demo' by 1 commit

So now I want to undo my last commit so how can I do that?

  • Resolve conflicts using remote changes when pulling from Git remote
  • git svn imported repository using svn branches
  • git partial merge, not whole branch
  • Is there a way to make git automatically retry commands if index.lock exists?
  • git add . vs git commit -a
  • How do I change the remote a git branch is tracking?
  • Visual Studio and libgit2 Git Commit Error In Different Solution
  • How do I do the equivalent of “git remote update” with jgit?
  • import all branches from github
  • How to see diff between working directory and staging index?
  • What graphical git tool for Mac can show per-file history better than github?
  • Git push reminder/helper?
  • 2 Solutions collect form web for “how to undo commit”

    If you want to undo it completely:

    git reset --hard HEAD^
    

    If you want to undo it and keep your changes staged (before commit):

    git reset --soft HEAD^
    

    If you want to undo it and keep your files modified (before stage):

    git reset --mixed HEAD^
    

    To revert your commit by creating another commit (assuming master is your working branch):

    git revert master
    

    To undo it, ie, pretend it never happened:

    git reset --hard master~
    
    Git Baby is a git and github fan, let's start git clone.