Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»GIT»How to Undo the Last Local Commits in Git

    How to Undo the Last Local Commits in Git

    By RahulJune 8, 20221 Min Read

    Sometimes you found that you have committed some wrong files for in-completed code in your local git repository. The following command will revert the last commit in your current working repository. If you just want to change last commit message, you can use this article to do it.

    Advertisement

    Undo the Last Local Commit in Git

    The git reset is used to reset the index entries and updates files in the working tree that are different between the <commit> and HEAD.

    1. So use the following command to reset the index to HEAD and delete all changes in the local working copy.
      git reset --soft HEAD~ 
      
    2. Now, edit the local files make the necessary changes
    3. Add them again using git add command.
      git add . 
      
    4. After that commit files as you always do, you can reuse the old commit message using -c ORIG_HEAD. This will open last commit message in the editor.
      git commit -c ORIG_HEAD 
      

    Wrap Up

    In this tutorial, you have learned to reset the last commit from the local repository.

    git
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Mastering Git and GitHub for Version Control

    Git Change Remote URL: How to

    Git Change Remote URL in Local Repository

    Git Change Remote URL to SSH (from HTTPS)

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.