[英]git: remove 2nd commit
我正在嘗試刪除第二次提交到回購。 在這一點上,我可以吹掉.git
目錄並重新執行它,但我很好奇如何做到這一點...我之前刪除了提交,但顯然從來沒有第二個:)
> git log
commit c39019e4b08497406c53ceb532f99801793205ca
Author: Me
Date: Thu Mar 22 14:02:41 2012 -0700
Initializing registry directories
commit 535dce28f1c68e8af9d22bc653aca426fb7825d8
Author: Me
Date: Tue Jan 31 21:04:13 2012 -0800
First Commit
> git rebase -i HEAD~2
fatal: Needed a single revision
invalid upstream HEAD~2
> git rebase -i HEAD~1
在這一點上,我進入我的編輯器:
pick c39019e Initializing registry directories
# Rebase 535dce2..c39019e onto 535dce2
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
現在我的問題是,我不能只是吹掉第二次提交,因為“如果你刪除所有內容,那么rebase將被中止”
要刪除最頂層的提交,請使用git reset --hard HEAD~
。 不需要Rebase,因為您沒有在其他提交之間刪除任何內容。
這已經回答了(上面),但請注意,在較新的git中,有一個noop
命令可以放入文件中。 所以你可以用noop
替換pick
線:
$ git rebase -i HEAD^
[in editor, change pick line to noop, and write and quit]
".git/rebase-merge/git-rebase-todo" 15L, 492C written
Successfully rebased and updated refs/heads/master.
$
不可否認, git reset
並不能輕易做到這一點......但是如果你已經啟動了交互式rebase,並且你只是意識到你想要的事情,那么noop
技巧就很方便了。
為什么不還原你的提交?
git revert 535dce28f1c68e8af9d22bc653aca426fb7825d8
或git revert HEAD~1
您還可以執行以下操作:
git rebase -i --root
這將包括您的rebase中的root提交。 如果您願意,您可以選擇完全fixup
, squash
或刪除第二次提交。
如果是最后一次提交,那么你可以這樣做:
git reset --hard HEAD~
如果它不是最后一次提交,你將在rebase列表中至少進行另一次提交,你可以刪除第二次提交。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.