古いgitコミットを削除する 質問する

古いgitコミットを削除する 質問する

私はgitの初心者なのですが、このようなことが可能なのか疑問に思っています。

>git log --pretty=oneline --abbrev-commit
2f05aba Added new feature
3371cec Fixed screw up    <-- I want to remove this
daed25c Screw up          <-- and remove this.
e2b2a84 First.                So it's like they never happend.

これは可能ですか?

ベストアンサー1

本当に削除したい場合(履歴から消去し、二度と見られないようにしたい場合)、

リベースを実行:

git rebase -i HEAD~4

そして、削除したいコミットに対応する行を次のように削除 (またはコメントアウト) します。

pick 2f05aba ... #will be preserved
#pick 3371cec ... #will be deleted
#pick daed25c ... #will be deleted
pick e2b2a84 ... #will be preserved

おすすめ記事