GIT:如何压缩已推送到远程存储库的多个提交?
我对 Git 有一个奇怪的设置。基本上我有:
[client 1] <---> [remote repo] ----> [client 2]
[Client 1] 本质上是我正在使用的本地存储库,因为我无法在本地计算机上编译/构建项目。
[客户端2]是用于构建的远程服务器。
中间,我有另一个存储库,[远程存储库],基本上用于与我公司的 cvs 中央存储库同步,以及在我的[客户端 1] 和 [客户端 2] 之间同步。
由于所有编译/构建都是在 [client 2] 上完成的,因此我在 [client 1] 上进行了许多琐碎的提交,只是为了修复编译或构建错误。
因此,当我发现上次提交中存在错误时,已经为时已晚,因为提交已经被推送到远程存储库并从远程存储库中提取。
我怎样才能将这些(许多)琐碎的提交压缩为一个? 谢谢。
I have a weird setup with 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.
[Client 2] is a remote server for building.
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].
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,除非绝对必要,否则避免挤压和重写历史。拥有“微不足道”的提交并不是压制推送提交的理由。如果他们能留下来,就让他们留下来。在 cvs 中重写历史根本不是一件简单的事,因此由于这些提交会进入 cvs 存储库,因此您可能应该接受它。
对于 git 远程存储库,如果您确实希望继续 - 我假设您知道压缩本地存储库上的提交( git rebase -i 很简单)。挤压后,用
-f
推动 - 用力推动。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.
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). After the squash, push with a-f
- a force push.您可以使用
git rebase -i
或 < code>git merge --squash,请参阅 使用 Git 将我最后的 X 次提交压缩在一起但是既然你已经将它们发布到另一个存储库,您必须在其他存储库上修复它。虽然相当麻烦,但 git push --force 是您需要的命令。
但是,不建议这样做:如果远程存储库已经与 CVS 同步,您也必须修复它...如果其他开发人员已经从中提取了同样的事情。
You can squash the commits with
git rebase -i
orgit merge --squash
, see Squash my last X commits together using GitBut 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.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.