简体   繁体   English

GIT:如何压缩已被推送到远程仓库的几个提交?

[英]GIT: how to squash several commits that have been pushed to a remote repo?

I have a weird setup with Git. 我和Git有一个奇怪的设置。 Basically I have: 基本上我有:

[client 1] <---> [remote repo] ----> [client 2]

[Client 1] is essentially the local repo I am working with, because I can't compile/build the project on my local machine. [客户端1]本质上是我正在使用的本地仓库,因为我无法在本地机器上编译/构建项目。

[Client 2] is a remote server for building. [客户端2]是用于构建的远程服务器。

In the middle, I have another repo, [remote repo], basically for synchronizing with a cvs central repo in my company, and also synchronizing between my [client 1] and [client 2]. 在中间,我有另一个回购,[远程回购],基本上用于与我公司的cvs中央回购同步,并且还在我的[客户端1]和[客户端2]之间进行同步。

Since all the compiling/building is done on [client 2], I have many trivial commits on [client 1] just for fixing the compilation or building errors. 由于所有编译/构建都在[客户端2]上完成,因此我在[客户端1]上进行了许多简单的提交,只是为了修复编译或构建错误。

So by the time I find out there are errors in the last commit, it's already too late because the commit has already been pushed to and pulled from the remote repo. 所以当我发现最后一次提交时出现错误时,已经太晚了,因为提交已经被推送到远程仓库并从中撤出。

How can I squash these (many) trivial commits into one? 我怎样才能将这些(很多)琐碎的提交压缩成一个? Thanks. 谢谢。

First of all, avoid squashing and in general rewriting history unless you absolutely have to. 首先,避免挤压和一般重写历史,除非你绝对必须。 Having "trivial" commits is not reason to squash pushed commits. 进行“微不足道的”提交并不是压制推送提交的理由。 If they can stay, let them stay. 如果他们能留下来,就让他们留下来。 And rewriting history is not straightforward in cvs at all, so since these commits would have made their way into the cvs repo, you should probably live with it. 并且在cvs中重写历史并不简单,所以既然这些提交已经进入了cvs repo,你应该忍受它。

For the git remote repo, if you do wish to proceed - I assume you know to squash the commits on your local repo ( git rebase -i is straightforward). 对于git远程仓库,如果你想继续 - 我假设你知道要压缩你当地仓库的提交( git rebase -i很简单)。 After the squash, push with a -f - a force push. 壁球后,用-f推动 - 推力。

You can squash the commits with git rebase -i or git merge --squash , see Squash my last X commits together using Git 你可以使用git rebase -igit merge --squash ,请参阅使用Git将我的最后一次X提交 git merge --squash 在一起

But since you have already published them to another repository you have to fix it on others. 但是,由于您已将它们发布到另一个存储库,因此您必须将其修复到其他存储库。 Quite cumbersome, but git push --force is the command you need, though. 相当麻烦,但git push --force是你需要的命令。

It is not recommended, however: if the remote repo has already synced with CVS you'll have to fix it too... Same thing if other devs have already pulled from it. 但是不建议:如果远程仓库已经与CVS同步,你也必须修复它......如果其他开发人员已经从它中撤出了同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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