git - Remove commit before HEAD

后端 未结 2 1840
执念已碎
执念已碎 2021-01-22 05:47

Okay I am new to Git and would like to know how to remove a commit before the HEAD. For instance-:

commit foo (This is the HEAD)

commit bar (This is what I want         


        
2条回答
  •  旧巷少年郎
    2021-01-22 06:27

    git rebase -i HEAD~2

    Will let you interactivly remove the commit

    git rebase will remove all reference of that commit and change the id of the HEAD commit. Meaning people MAY have issues if they have branched from the old commit

    git revert

    may be a better way to keep history

提交回复
热议问题