简体   繁体   中英

Git command line equivalent of Sourcetree's reverse hunk between two arbitrary commits

Suppose two branches, B and D, share a common ancestor commit A:

A -- B
  \_ C -- D

In Sourcetree, in addition to seeing the changes between B and D ( git diff B..D ), there's also an option to reverse the hunks and lines in the diff ie apply the diffed changes between B and D onto commit B or vice versa.

Using Sourcetree to reverse the hunks in the diff didn't cause any conflicts but my attempt to use git revert B..D from the command line resulted in a conflict. Is there a way to do accomplish this via the command line without causing conflict?

Create a patch from the diffed output and apply it:

git checkout B
git diff B..D > temp.patch
git apply temp.patch
rm temp.patch
# select hunks
git add -p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM