开发者

Git reverse merge of subtree

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 b开发者_如何学JAVAetween 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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜