リベースを使用して、1つのステップでそれを行うことができます。
git rebase --onto A C D
私はこれをテストしたところ、適切な結果が得られました。
$ edit test.txt
$ git add .
$ git commit -mA
$ git checkout -b the_branch
$ edit test.txt
$ git commit -a -mB
$ git checkout master
$ git merge master the_branch --no-ff
$ edit test.txt
$ git commit -a -mD
ここから、あなたが説明した状況があります。それで:
$ git rebase --onto <SHA1-for-A> <SHA1-for-C> master
コミットをC(除外)からマスター、Aにリベースします。BとDの同じ場所で変更したため、いくつかの競合を修正する必要がありましたが、修正しないと思います。
_D'
/
/
A_______C___D
\ /
\_B_/
git rebase --onto
多かれ少なかれあなたの状況である
についてのドキュメント:http: //git-scm.com/docs/git-rebase
あなたが持っていた場合:
A_______C___D___F
\ /
\_B_/
、そしてあなたは今持っています:
_D'___F'_(master)
/
/
A_______C___D___F
\ /
\_B_/(the_branch)
ここから、マスターの変更をブランチにマージするのは簡単です。コミットF'
を完全に破棄します。
$ git checkout master # if you were not here already
$ git branch old_fix # if you want to be able to return to F' later
$ git reset --hard <SHA1-to-D'>
上記のコマンドの後、次のようになります。
(master)
/
_D'___F'_(old_fix)
/
/
A_______C___D___F
\ /
\_B_/(the_branch)
masterの更新をthe_branchにマージするには:
$ git checkout the_branch
$ git merge master
...そして競合を修正します。