How to permanently remove few commits from remote branch
I know that's rewriting of history which is bad yada yada.
But how to permanently remove few commits from remote branch?
You ' git reset
' your local branch, and you git push --force
your revised local branch to the remote. (other solution here, involving deleting the remote branch, and re-pushing it)
This SO answer illustrates the danger of such a command, especially if people depends on the remote history for their own local repos.
You need to be prepared to point out people to the RECOVERING FROM UPSTREAM REBASE section of the git rebase
man page
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
git revert dd61ab23
2 Delete the last commit
git push <<remote>> +dd61ab23^:master
or, if the branch is available locally
git reset HEAD^ --hard
git push <<remote>> -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 <remote_repo> <remote_branch> -f
Just note to use the last_working_commit_id
, when reverting a non-working commit
git reset --hard <last_working_commit_id>
So we must not reset to the commit_id
that we don't want.
Then sure, we must push to remote branch:
git push --force
链接地址: http://www.djcxy.com/p/48922.html
上一篇: 硬和远程存储库
下一篇: 如何从远程分支永久删除少量提交