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

Mark E. Haase
  • 25,965
  • 11
  • 66
  • 72
  • 1
    Would http://stackoverflow.com/questions/642264/undo-change-in-git-not-rewriting-history/642809#642809 help? Not a definitive answer, but still. – VonC Aug 25 '10 at 22:01
  • After reading that, I think the answer to my question is, "No, git doesn't do it any easier than patch." – Mark E. Haase Aug 27 '10 at 07:09

1 Answers1

2

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
  • 398,885
  • 90
  • 523
  • 479
  • 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. – Cascabel Aug 26 '10 at 01:31
  • That would blow away all my changes from the previous 4 commits, though. – Mark E. Haase Aug 27 '10 at 07:03