version control - Git "revert" current directory

ID : 131334

viewed : 7

Tags : gitversion-controlresetgit-checkoutrevertgit

Top 5 Answer for version control - Git "revert" current directory

vote vote

97

Like vcsjones says, the solution here is git checkout:

git checkout <refspec> -- path/to/directory  # or path/to/file 

where <refspec> can, for instance, be HEAD, that is, the current working commit. Note that this usage of the checkout command will affect the working tree but not the index.

git revert is used to "revert a commit", and by this, it should not be understood that the commit disappears from the tree (it would play havoc with history -- if you want that, look at git rebase -i). A reverted commit consists of applying, in reverse, all changes from the commit given as an argument to the tree and create a new commit with the changes (with a default commit message, which you can modify).

vote vote

90

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.

vote vote

79

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
vote vote

63

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

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

54

Top 3 video Explaining version control - Git "revert" current directory

Related QUESTION?