Different Methods for Resetting Files in Git

Confused by the various options for cleaning up or resetting your branch, working area, or staging area?

Use this overview to help get things sorted:


CommandDescriptionAffects Working AreaAffects Staging AreaExample Call
git reset (no options)Resets the current branch to a specific commit and removes changes from the Staging Area, but keeps changes in the Working Area.NoYesgit reset <commit-hash>
git reset --softResets the current branch to a specific commit, but keeps both the Staging Area and the Working Area unchanged.NoNogit reset --soft HEAD~1
git reset --hardResets the current branch to a specific commit and discards all changes in the Working Area and the Staging Area.YesYesgit reset --hard <commit-hash>
git reset (last commit)Resets the current branch to the last commit. By default, it affects the Staging Area but not the Working Area.NoYesgit reset HEAD~1
git reset HEADRemoves changes from the Staging Area but keeps them in the Working Area.NoYesgit reset HEAD <filename>
git checkout --Resets changes in files in the Working Area to the last state of the HEAD commit. Does not affect the Staging Area.YesNogit checkout -- <filename>
git restoreA newer alternative to git checkout -- for resetting changes in files in the Working Area. Can also be used to remove changes from the Staging Area.Yes, if without --stagedOptional, with --stagedgit restore <filename>
git cleanRemoves untracked files and directories from the working directory.Yes (only untracked files/directories)Nogit clean -df

Each of these commands has specific use cases in managing the state of files in a Git repository, affecting either the Working Area, the Staging Area, or both.

Also take a look at our GIT training in Vienna or Remote: GIT Training – ciit-training.com

For further reading we recommend the free Pro Git Book: Pro Git free book

Illustration cleaning up with git.

Nginx Cache für WordPress

In der Welt des Webhostings ist die Geschwindigkeit ein entscheidender Faktor für den Erfolg einer Website. Hier kommt der Nginx-Cache ins Spiel, insbesondere für WordPress-Websites.

Weiterlesen »

Virtuelle Threads in Java 21

Virtuelle Threads in Java: Ein Paradigmenwechsel in der Concurrent Programmierung   Einführung in Virtuelle Threads Mit der Einführung von virtuellen Threads in Java (auch als

Weiterlesen »

@Transactional in Spring – how it works

This article provides an in-depth exploration of Spring Framework’s @Transactional annotation, detailing its functionality, implementation, advanced features, and best practices for effective transaction management in Java applications.

Weiterlesen »