如果您还没有推送任何内容,您可以在multiple ways 中修改您的历史记录。如果你推动了你的状态,你需要考虑它会产生的影响!
对于在branch1 之上创建提交但尚未推送它们的任何协作者,您将遇到麻烦。如果除了你之外没有人使用过branch1,你应该没问题。
我找到了最直观的使用方式
git checkout branch1
git rebase -i master
这会打开一个像这样的文本文件。如下所示,将您想要删除的提交更改为drop。然后保存文件并退出。
drop 1a432d7 revertB
pick 2657446 c
pick 8d15847 d
# Rebase 1219262..8d15847 onto 1219262 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
由于我在我的测试存储库中始终为这个答案修改了同一行,所以我遇到了合并冲突。在提交 b 中,我写了b。在提交 c 中,我写了c。在提交 revertB 中,我写了revertB。
<<<<<<< HEAD
b
=======
c
>>>>>>> 2657446... c
如果遇到任何合并冲突,您将不得不修复。就我而言,我将文件内容替换为c。
暂存固定文件后继续变基:
git add myfile
git rebase --continue
您可以选择修改提交 c 的提交消息。确认后,revertB 将从 branch1 消失。