简体   繁体   English

Git将旧的本地提交推送到远程分支的最新版本

[英]Git push old local commit to more current version of remote branch

I made a commit to my local repository that was not integrated into the remote repository. 我对未集成到远程存储库的本地存储库进行了提交。 Now lots of work has been done on the remote repository, and when I do a "git pull", I have tons of staged changes now because they fail to merge automatically with my lone, local commit. 现在,远程存储库上已经完成了许多工作,当我执行“ git pull”操作时,由于没有将它们与我自己的本地提交自动合并,所以我现在进行了大量的分阶段更改。

在此处输入图片说明

Is there a way to look at the most current revision on the remote branch and manually merge my commit into it? 有没有办法查看远程分支上的最新修订并将我的提交手动合并到其中? Reading about cherry-pick and rebase I cannot decide if they apply to my situation. 在阅读有关摘樱桃和变基的文章时,我无法确定它们是否适用于我的情况。 I could do a fresh checkout of the project, and then copy/paste my code changes from one repo to another but I want to hear the correct way of doing it in case I have a larger commit in the future. 我可以对项目进行全新签出,然后将代码更改从一个存储库复制/粘贴到另一个存储库,但是我想听听这样做的正确方法,以防将来我有更大的提交。

First, save your current work in another local branch not to loose it. 首先,将您当前的工作保存在另一个本地分支中,不要使其丢失。

git checkout -b i-would-never-commit-to-develop-locally

Then, synchronize your local develop with the remote. 然后,将本地develop与远程同步。

git fetch -f origin develop:develop

Rebase your branch to the develop . 将分支机构重新建立为develop

git rebase develop

It is likely that you would have to resolve some conflicts here. 您可能必须在这里解决一些冲突。

Finally, push your commit to the remote. 最后,将您的提交推送到远程。

git push origin HEAD:remote-target-branch

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

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