How to permanently remove few commits from remote branch

后端 未结 8 1769
予麋鹿
予麋鹿 2020-11-27 09:07

I know that\'s rewriting of history which is bad yada yada.

But how to permanently remove few commits from remote branch?

8条回答
  •  无人及你
    2020-11-27 09:18

    Important: Make sure you specify which branches on "git push -f" or you might inadvertently modify other branches![*]

    There are three options shown in this tutorial. In case the link breaks I'll leave the main steps here.

    1. Revert the full commit
    2. Delete the last commit
    3. Delete commit from a list

    1 Revert the full commit

    git revert dd61ab23
    

    2 Delete the last commit

    git push <> +dd61ab23^:<>
    

    or, if the branch is available locally

    git reset HEAD^ --hard
    git push <> -f
    

    where +dd61... is your commit hash and git interprets x^ as the parent of x, and + as a forced non-fastforwared push.

    3 Delete the commit from a list

    git rebase -i dd61ab23^
    

    This will open and editor showing a list of all commits. Delete the one you want to get rid off. Finish the rebase and push force to repo.

    git rebase --continue
    git push   -f
    

提交回复
热议问题