在其他提交之间删除提交 [英] Deleting a commit in Between other commits
问题描述
我有一个本地和它相应的github回购。我有一些提交作为
A < - B < - C < - D
A是最新的。
这两种情况都是回购。我想删除提交C,就好像它从未发生过一样。
所以它应该像 git log
A < - B < - D
$
我试过 git reset --soft< sha-commit-C>
,现在卡住了。我看不到 A,B
。在做任何进一步的步骤之前,我想要充分确定我知道我在做什么。
git reflog
给出我:
git reflog
73ea54d HEAD @ {0}:reset:移至73ea54d8
a594699 HEAD结账:从unique_ptr_release移动到a594699fb6f7d85bc8
a594699 HEAD @ {3}:checkout:{@} {1}:rebase -i(完成):返回refs / heads / unique_ptr_release
a594699 HEAD @ {2}从unique_ptr_release移动到unique_ptr_release
a594699 HEAD @ {4}:commit(合并):将分支'master'合并到unique_ptr_release
HEAD @ {4}
是我的Head在 reset --soft
命令之前的内容。
如何摆脱这种情况?
git-rebase 是你在找什么。在您提交 ABCD
的情况下,并且想要移除C,请尝试:
git rebase -i HEAD〜3
它会通过编辑器显示最后3次提交(我的vim),
只是删除(在vim中: dd
)你想要的提交行删除
然后保存它(在vim中::wq
)。完成后,查看 git log
,您将看到 C
提交已被移除。
*不要忘记备份您的代码或.git文件夹。
I have a local and its corresponding github repo. I have some commits as
A <- B <- C <- D
A being the latest.
This is situation on both the repos. I want to delete commit C as if it never happened.
So it should be like on git log
A <- B <- D
on both repos.
I tried git reset --soft <sha-commit-C>
and am now stuck. I can not see A, B
. Before doing any further steps i want to be fully sure that i know what i am doing.
git reflog
gives me :
git reflog
73ea54d HEAD@{0}: reset: moving to 73ea54d8
a594699 HEAD@{1}: rebase -i (finish): returning to refs/heads/unique_ptr_release
a594699 HEAD@{2}: checkout: moving from unique_ptr_release to a594699fb6f7d85bc8
a594699 HEAD@{3}: checkout: moving from unique_ptr_release to unique_ptr_release
a594699 HEAD@{4}: commit (merge): Merge branch 'master' into unique_ptr_release
HEAD@{4}
is what my Head was before reset --soft
command.
How do i get out of this situation ?
Git-rebase is what are you looking for.
in your case of commit A-B-C-D
, and want to remove C, try:
git rebase -i HEAD~3
it will show the last 3 of your commits via editor (mine is vim),
just delete (in vim: dd
) the line of commit you want to remove,
then save it (in vim: :wq
).
Done, view the git log
and you will see that the C
commit is removed.
*don't forget to backup your code or .git folder.
这篇关于在其他提交之间删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!