Git - How to revert entire directory to specific commit (removing any added files)

I figured out the simplest solution.

git rm /path/to/dir
git checkout <rev> /path/to/dir
git commit -m "reverting directory"

Then delete any untracked files.

git rm

Remove files from the working tree and from the index https://git-scm.com/docs/git-rm

git checkout 

Updates files in the working tree to match the version in the index or the specified tree. https://www.git-scm.com/docs/git-checkout

git commit

Record changes to the repository https://www.git-scm.com/docs/git-commit


remove only the folder and its content on git

git rm -r --cached myFolder

remove folder on git and locally

git rm -r myFolder

then commit and push again

To Revert to a previous commit

#reset to previous commit, replace with your commit hash code, you can find it from your commit history 
git reset {commit hash} 

#moves pointer back to previous head branch
git reset --soft HEAD@{1}

git commit -m "Reverted commit to blah"

#update your working copy
git reset --hard

Reverting to part of a commit In that case you need to revert to a particular commit and add patch

#reset to previous commit, but don't commit the changes
$ git revert --no-commit {last commit hash}   

# unstage the changes
$ git reset HEAD .             

# add/remove stuff here
$ git add file
$ git rm -r myfolder/somefiles          

# commit the changes  
$ git commit -m "fixed something"

# check the files
$ git status

#discard unwanted changes
$ git reset --hard             

Tags:

Git