如何删除第一个提交并使其直接子节点成为根 [英] how to delete the first commit and make its immediate child the root
问题描述
我从git commit获得了 commit-id1
,但这是第一个提交,因此它没有父级.有一个 commit-id2
是其直接子代.
I have commit-id1
from a git commit but this is the first commit so it has no parent. There is a commit-id2
whose is its immediate child.
这是场景 commit-id1 ---->commit-id2 ---->commit-id3 ...
有一种安全的方法来删除 commit-id1
并使 commit-id2
为第一次提交
is there a safe way to delete commit-id1
and make commit-id2
the first commit
,即 commit-id2 ---->commit-id3 ...
我了解了 git rebase -onto
,但它需要一个父级,并且无法弄清楚
I read about git rebase -onto
but it requires a parent and not able to figure it out
提交已推送到服务器,我也想将其从服务器中删除
The commits are pushed to the server and I would like to delete it from the server too
推荐答案
您应该这样做
$ git rebase -i --root
这将启动交互式变基.您的文本编辑器将打开,其中包含所有将被重新基础化的提交以及说明的列表.编辑文件,以便跳过第一次提交.现在保存文件并关闭文本编辑器.
This starts an interactive rebase. Your text editor will open with a list of all commits that will be rebased as well as instructions. Edit the file so that the first commit is skipped. Now save the file and close your text editor.
这将从您的本地历史记录中删除提交.如果您需要更新遥控器,则必须强制推送,就像任何本地历史记录修订一样:
This will remove the commit from your local history. If you need to update a remote, then you will have to force push, just like with any local history revision:
$ git push origin master
用适当的远程名称替换 origin
,并用适当的分支名称替换 master
.
Replace origin
with the appropriate remote name and master
with the appropriate branch name.
这篇关于如何删除第一个提交并使其直接子节点成为根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!