Deleting a commit in Between other commits

后端 未结 2 811
情书的邮戳
情书的邮戳 2020-12-19 15:24

I have a local and its corresponding github repo. I have some commits as

A <- B <- C <- D

A being the latest.

This is situ

相关标签:
2条回答
  • 2020-12-19 15:33
    1. Ensure you back up your .git folder.
    2. Ensure commit D , don’t rely upon the changes made in C.
    3. git rebase --onto D B~1 (as A is the latest commit)
    0 讨论(0)
  • 2020-12-19 15:51

    Git-rebase is what are you looking for.

    in your case of commit A-B-C-D, and want to remove C, try:

    git rebase -i HEAD~3
    

    it will show the last 3 of your commits via editor (mine is vim), just delete (in vim: dd) the line of commit you want to remove, then save it (in vim: :wq).

    Done, view the git log and you will see that the C commit is removed.

    *don't forget to backup your code or .git folder.

    0 讨论(0)
提交回复
热议问题