Remove old git commits

前端 未结 4 1885
后悔当初
后悔当初 2020-12-07 17:59

I\'m very new to git, and was wondering if something like this is possible?

>git log --pretty=oneline --abbrev-commit
2f05aba Added new feature
3371cec Fi         


        
4条回答
  •  余生分开走
    2020-12-07 18:44

    To completely delete commit(s) there is a new option drop for git interactive rebases now. First run:

    git rebase -i HEAD~4
    

    Then replace pick with drop for the commit(s) to be dropped:

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

    This worked on Fedora for me with the following version:

    $ git version
    git version 2.21.0
    

提交回复
热议问题