简体   繁体   中英

How do you delete a remote commit if you deleted a remote branch?

I pushed a branch based off another branch to GitHub. It has one commit, but shortly after I realized I pushed the wrong version of that branch. I immediately deleted the branch using git push origin --delete <branch_name> but saw in one of my project tracker programs that the commit I made is still there.

I unfortunately did not think to delete the commit locally and push, then delete the branch locally and push.

Now that the remote branch is deleted, how do I also delete the remote commit?

If I understand correctly, through my research here: Does deleting a branch in git remove it from the history? my commit should be an unreachable/dangling commit but I have not been able to find any answers where I can delete a remote commit.

I have saw that you can use git gc but is that enough to get rid of the remote commit? Is it possible to keep the local branch and local commit but delete the remote commit?

My end result is that I'd like the remote branch to be deleted (seems good) and the remote commit to be deleted (needs help). Thank you!

Deleting the remote branch is one step.

Locally, you need to reset your branch to some past commit (which represents the right version) and push again.

git checkout myBranch
git reset --hard <pastCommitSHA1>

On the remote side, make sure none of your commits are still referenced by:

  • other branches
  • a tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM