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/90388.html

    上一篇: 如何检查给定远程存储库上是否存在远程分支?

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