1

Being in branch B, I realized I need to fix commit that exists in both branches A and B. Here what I tried to do, but with no result (only fourth commit's hash changes):

#!/bin/bash -eu
rm -rf 1
mkdir 1
cd 1
git init

echo 1 >1
git add .
git commit -am 1
echo 2 >2
git add .
git commit -am 2
echo 3 >3
git add .
git commit -am 3

git checkout -b B

echo 22 >2
git add .
git commit -am 2

git rebase -i HEAD~3   # fix second commit with fourth one, like this:
                       # pick 485dacc 2
                       # f 976dc2a 2
                       # pick d899817 3

git rebase master || true
echo 22 >2
git add .
git rebase --continue
4

1 回答 1

2

就在您第一次变基之前,您的历史记录如下所示:

* ab5f408 (HEAD, B) 2
* ef59c1a (master) 3
* 0a3437c 2
* f62884f 1

然后:

git rebase -i HEAD~3   # fix second commit with fourth one, like this:
# pick 485dacc 2
# f 976dc2a 2
# pick d899817 3

现在看起来像:

* 33211f1 (HEAD, B) 3
* af315cd 2
| * ef59c1a (master) 3
| * 0a3437c 2
|/  
* f62884f 1

掌握我认为你想要的地方:

git checkout master
git reset --hard B

这给你留下了:

* 33211f1 (HEAD, master, B) 3
* af315cd 2
* f62884f 1
于 2013-05-23T20:01:06.203 回答