Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I want revert a directory in git - reverting all files inside, as well as removing any files added since that commit. Doing a checkout only seems to satisfy my first requirement, but doesn't delete any files.

like image 721
ademartini Avatar asked Sep 25 '14 21:09

ademartini


People also ask

How do I revert a repository to a specific commit?

Right click on the commit you want to return to and select "Reset master branch to here". Then choose hard from the next menu.

How do I revert a directory in git?

How would I revert just the current directory in Git? Use git checkout instead of reset. git checkout <branchname>~1 -- path/to/directory/you/want/updated should do the trick.

How do I revert a git commit after add?

Undoing a commit If you have modified, added and committed changes to a file, and want to undo those changes, then you can again use git reset HEAD~ to undo your commit.


1 Answers

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

like image 192
ademartini Avatar answered Sep 25 '22 06:09

ademartini