Delete commits from a branch in Git

后端 未结 30 2075
醉话见心
醉话见心 2020-11-21 07:17

I would like to know how to delete a commit.

By delete, I mean it is as if I didn\'t make that commit, and when I do a push in the future, my changes wi

30条回答
  •  梦如初夏
    2020-11-21 07:59

    As you can see on above image i want to delete revert"test change 2" commit(SHA1 ID: 015b5220c50e3dfbb1063f23789d92ae1d3481a2(you can get SHA1 ID by using gitk command in git bash)).

    For that i can use(all below command work on local only. you need to push after delete):

    1. git reset --hard 515b5220c50e3dfbb1063f23789d92ae1d3481a2 //it back-up you to that commit (SHA1 ID of test change 4 commit is 515b5220c50e3dfbb1063f23789d92ae1d3481a2)
    2. git reset --hard HEAD~1 // it back-up you before one commit.
    3. git reset --hard HEAD^ // To remove the last commit from git

    after delete:

提交回复
热议问题