Git: remove earlier commit but keep recent changes

前端 未结 8 1497
甜味超标
甜味超标 2020-12-03 10:50

I got some commits in my repository:

like:

A - Added Feature A
B - Removed Feature B
C - Redesigned Feature C
D - Added Feature D
E - Added Feature          


        
8条回答
  •  春和景丽
    2020-12-03 11:26

    git reabse -i HEAD~3
    

    you will have the list of your 3 last commit messages

    C - Redesigned Feature C
    D - Added Feature D
    E - Added Feature D
    

    you just insert x git reset HEAD^ before the commit you want to undo, you want to undo commit C, so it will be like this

        C - Redesigned Feature C
    x git reset HEAD^
        D - Added Feature D
        E - Added Feature D
    

    exit rebase console, you will see that your commit is no more in the log and their files are staged.

提交回复
热议问题