'Git "revert" current directory

In Subversion (SVN), it's possible to do svn revert ./* in which the current directory and only the current directory gets reverted.

What is the Git equivalent to svn revert in which only the current directory gets reverted?

I know that there's git reset --hard, but it reverts everything and not just the current directory.

How would I revert just the current directory in Git?



Solution 1:[1]

Go to the folder you want to revert and do this:

git checkout -- .

See more in krlmlr's answer to How to git reset --hard a subdirectory.

Solution 2:[2]

When I was a Git novice (and afraid of the terminal) I found the easiest way was to:

  • switch to the branch you want to revert your specific subdirectory to
  • copy the subdirectory you want to revert to your desktop
  • switch back to your branch
  • overwrite the subdirectory you want to replace in your Git directory with the one you copied to your desktop

Solution 3:[3]

If you want to do it recursively from a specific directory:

git checkout -- ./*
git checkout -- mydir/*

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen
Solution 2 Peter Mortensen
Solution 3 Peter Mortensen