[英]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. 我发现了其他一些有关在Git中进行反向合并的问题,但是这些问题都在询问如何反向合并整个提交。 I want to reverse merge one directory in my tree.
我想反向合并树中的一个目录。 Is this possible in Git?
在Git中可能吗?
In subversion, you can do this: 在Subversion中,您可以执行以下操作:
$ 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. 并且这将计算修订版801和802之间的反向差异,并将其仅应用于当前目录。
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?
git可以做得更好吗?
You can use git checkout
to checkout an entire directory at a specified revision. 您可以使用
git checkout
来检出指定修订版本的整个目录。 For example, to revert the directory src
to a commit five commits back: 例如,要将目录
src
还原为一次提交,需要进行五次提交:
$ git checkout HEAD~5 -- src
$ git status # See what files changes
$ git diff --cached # Review the changes
$ git commit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.