How to squash specific commits that have been pushed to remote?

I have made the following commits in my branch and pushed them to remote

commit 5
commit 4
commit 3
commit 2
commit 1

I now want to squash commits 1, 2 & 3 and remove commits 4 & 5 (dont need the changes anymore) How can i do this?


Once pushed, you cannot easily change the history without affected other users, so it becomes a communication problem.

One approach would be:

  • to squash and drop your commit in a separate branch
  • push that branch for others to examine
  • when everyone agrees on the new history, rename the branch (locally and remotely)
  • "git: renaming branches remotely?"
  • "Git: Rename “ master ” branch for both local and remote repository"
  • ask everybody to reset --hard their branch to the new origin/branch
  • 链接地址: http://www.djcxy.com/p/15834.html

    上一篇: “origin”是本地分支还是远程分支之后的分支?

    下一篇: 如何压缩已推送到远程的特定提交?