tags:

views:

21

answers:

1

I found some other questions that talk about a reverse merge in Git, but those questions are asking how to reverse merge an ENTIRE commmit. I want to reverse merge one directory in my tree. Is this possible in Git?

In subversion, you can do this:

$ cd /workingcopy/some/subtree
$ svn merge -r802:801 .

And this calculates the reverse diff between revision 801 and 802 and only applies it to the current directory.

The best I can come up with is

$ cd /gitrepo/some/subtree
$ git diff <commit-sha1> <commit-sha1>^ . > patchfile
$ patch -p1 < patchfile

Although I haven't actually tested this yet. Can git do something better?

+2  A: 

You can use git checkout to checkout an entire directory at a specified revision. For example, to revert the directory src to a commit five commits back:

$ git checkout HEAD~5 -- src
$ git status           # See what files changes
$ git diff --cached    # Review the changes
$ git commit
mipadi
You want `git diff --cached`. `git checkout` on a path works by loading it into the index, then copying that into the work tree. That means that `git diff` will show nothing, because the index and work tree match.
Jefromi
That would blow away all my changes from the previous 4 commits, though.
mehaase