我有一种情况,我想撤消分支上的第一次提交。一个简单的解决方案是创建一个新分支,然后将除第一个提交之外的所有提交从我的第一个分支移至新分支,然后删除旧分支。
我想象通过简单地弯曲分支的底部可以更好地完成此操作。这样的事情可能吗?我试图勾勒出它:
当前:
master a - b
branch1 \ revertB - c - d
通缉:
master a - b
branch1 \ - c - d
可能?:
master a - b ---------------------
skip \ revertB \
branch1 \ - c - d
我不需要revertB提交。我怎样才能做到这一点,或者这是不好的做法?提前致谢 :)
如果您还没有执行任何操作,则可以通过多种方式来修改历史记录。如果您推动了自己的状态,则需要考虑它将产生的影响!
对于在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
。在commit revertB中,我写道revertB
。
<<<<<<< HEAD
b
=======
c
>>>>>>> 2657446... c
如果遇到任何合并冲突,则必须进行修复。就我而言,我将文件内容替换为c
。
转储固定文件后,继续重新设置基准:
git add myfile
git rebase --continue
您可以选择修改提交c的提交消息。确认后,便revertB
不再存在branch1
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句