In a git repository I have a subdirectory that I want to reset to a specific state in the past (an earlier commit). Is it possible to undo all commits on files in a specific
The simplest way to do it to use the ability of git checkout
to be applied on a subdirectory. Then stage and commit:
git checkout <old-SHA1> -- path/to/subdir
git add -A path/to/subdir
git commit -m "reverted files in path/to/subdir to what it was at <old-SHA1>"
If you work out all of the commits that you want to undo, you can use git revert to back them out - this would be most useful if there was only one or two commits that were the troublemakers.
CharlesB's answer is a simpler approach to take if there are lots of commits, or the commits touch other parts of the project (but you could actually work around that by using the -n (don't autocommit) flag, and only committing the changes you are interested in)