如何合并提交并推送到远程 [英] how to combine commits and push to the remote

查看:106
本文介绍了如何合并提交并推送到远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一开始本地分支是最新的,现在我使用git rebase -i HEAD~3并将两个最新提交的pick修改为fixup以在本地分支合并3个提交,现在我要推送本地分支到远程.我只想在远程显示组合提交. 但是,合并后,本地分支落后于远程两次提交,因此我无法直接推送.我该如何处理?

At the beginning the local branch is uptodate and now I use git rebase -i HEAD~3 and modify the pick of the two newest commits to fixup to combine 3 commits at the local branch,and now I want to push the local branch to the remote. And I only want to show a combined commit at the remote. However,after combined the local branch falls behind with remote by two commits and I cannot push directly. How can I deal with it?

推荐答案

免责声明:git push --force很危险;使用它需要您自担风险.

DISCLAIMER: git push --force is dangerous; use it at your own risk.

如果您确实想执行此操作并合并提交,则可以先使用git squash然后使用git push --force在本地存储库中进行操作,以覆盖远程服务器上的内容.

If you really want to do this and combine commits, you could do it on your local repository using git squash and then git push --force in order to overwrite the content on the remote.

-

请注意,git push --force将更新分支以指向您的新提交,因此,除非您具有提交标识符或找到它的方式并且尚未对垃圾进行收集,否则将永远无法访问旧提交.尽管GitHub确实有活动日志,但是在托管的git服务上这通常是不可能的.

Note that git push --force will update the branch to point to your new commits, so the old commits will be inaccessible permanently unless you have the commit identifier or a way to find it and the commit hasn't been garbage-collected. This is generally not possible on hosted git services, though GitHub does have an activity log.

此外,如果其他人在同一分支上工作并且不期望更改,则git push --force可能会引起问题.

In addition, git push --force can cause issues if other people are working on the same branch and are not expecting the change.

这篇关于如何合并提交并推送到远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆