Reset all changes after last commit in git

Reset all changes after last commit in git

Asked on January 10, 2019 in Git.
Add Comment


  • 3 Answer(s)

    First reset the changes:

    git reset HEAD --hard
    
    

    Be careful with this command to keep files that are not tracked due to .gitignore.

    git clean -fd
    
    
    Answered on January 10, 2019.
    Add Comment

    Including Deleting added files, resetting modified files, and adding back deleted files to undo every change with the last commit.

    undo changes to tracked files:

    git reset HEAD --hard
    

    To remove untracked files:

    git clean -f
    

    To remove untracked files and directories:

    git clean -fd
    

    They cannot undo change to untracked files.

    To remove ignored and untracked files and directories

    git clean -fdx
    

    They can’t undo change to ignored files.

    User can also clean.requireForce to false:

    git config --global --add clean.requireForce false
    

    Use git clean to avoid using -f (–force)

    Answered on January 10, 2019.
    Add Comment
    1. You can undo changes to tracked files with:
      git reset HEAD --hard
      
    2. You can remove untracked files with:
      git clean -f
      
    3. You can remove untracked files and directories with:
      git clean -fd
      

      but you can’t undo change to untracked files.

    4. You can remove ignored and untracked files and directories
      git clean -fdx
      

      but you can’t undo change to ignored files.

    You can also set clean.requireForce to false:

    git config --global --add clean.requireForce false
    

    to avoid using -f (--force) when you use git clean

    Answered on February 20, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.