如何使用 rebase 删除提交
How to remove commits with rebase
我有以下提交树:
D (HEAD, origin/develop, develop)
| \
| C
B |
| /
A (origin/master, origin/HEAD, master)
我想从历史记录中删除提交 B 和 C,并保留对它们所做的更改。所以D源文件运行后还是一样的。只会更改 git 历史记录。
我试过:
git rebase -i A
来自 D,选项为:
pick B
pick C
然后我有一个合并错误:
warning: Cannot merge binary files: MyFile.bin (HEAD vs. C... )
Automatic cherry-pick failed. After resolving the conflicts,
mark the corrected paths with 'git add <paths>', and
run 'git rebase --continue'
Could not apply C...
所以我纠正了我的冲突,做了一个 git rebase --continue
并且我得到:
E (HEAD, develop)
| D (origin/develop)
| |\
|/ /
| C
B |
| /
A (origin/master, origin/HEAD, master)
而我想要:
E (or D, the sources files are the same in D & E)
|
A
我不明白为什么B还在从A到E的路上。我现在该怎么办?我有点困惑
根据评论,我这样做了:
git rebase -i A
pick B
squash C
然后我纠正了冲突 运行 git rebase --continue
之后树看起来像这样:
E (HEAD, develop)
| D (origin/develop)
| |\
| | C
| |/
|/|
| B
|/
A (origin/master, origin/HEAD, master)
为了让 origin/develop 指向 E,我做了一个 git push --force
。在那之后,我得到了我想要的:
E (HEAD, origin/develop, develop)
A (origin/master, origin/HEAD, master)
我有以下提交树:
D (HEAD, origin/develop, develop)
| \
| C
B |
| /
A (origin/master, origin/HEAD, master)
我想从历史记录中删除提交 B 和 C,并保留对它们所做的更改。所以D源文件运行后还是一样的。只会更改 git 历史记录。
我试过:
git rebase -i A
来自 D,选项为:
pick B
pick C
然后我有一个合并错误:
warning: Cannot merge binary files: MyFile.bin (HEAD vs. C... )
Automatic cherry-pick failed. After resolving the conflicts,
mark the corrected paths with 'git add <paths>', and
run 'git rebase --continue'
Could not apply C...
所以我纠正了我的冲突,做了一个 git rebase --continue
并且我得到:
E (HEAD, develop)
| D (origin/develop)
| |\
|/ /
| C
B |
| /
A (origin/master, origin/HEAD, master)
而我想要:
E (or D, the sources files are the same in D & E)
|
A
我不明白为什么B还在从A到E的路上。我现在该怎么办?我有点困惑
根据评论,我这样做了:
git rebase -i A
pick B
squash C
然后我纠正了冲突 运行 git rebase --continue
之后树看起来像这样:
E (HEAD, develop)
| D (origin/develop)
| |\
| | C
| |/
|/|
| B
|/
A (origin/master, origin/HEAD, master)
为了让 origin/develop 指向 E,我做了一个 git push --force
。在那之后,我得到了我想要的:
E (HEAD, origin/develop, develop)
A (origin/master, origin/HEAD, master)