如何解决git错误:“更新被拒绝,因为您当前分支的提示落后" [英] How to resolve git error: "Updates were rejected because the tip of your current branch is behind"

查看:44
本文介绍了如何解决git错误:“更新被拒绝,因为您当前分支的提示落后"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位善意的同事将更改推送到 Master 而不是创建分支.这意味着当我尝试提交时会出现错误:

A well meaning colleague has pushed changes to the Master instead of making a branch. This means that when I try to commit I get the error:

更新被拒绝,因为您当前分支的提示落后

Updates were rejected because the tip of your current branch is behind

我知道这应该通过提出重新同步的请求来解决,但我不想丢失我在本地所做的更改,我同样不想强制提交并清除所做的更改别人的.

I know this should be resolved by making a pull request to re-sync things but I don't want to lose the changes I have made locally and I equally don't want to force the commit and wipe out the changes made by someone else.

允许我合并更改而不丢失任何更改的正确方法是什么?

What is the correct approach to allow me to merge the changes without losing either?

推荐答案

如果你已经提交了一些提交,你可以执行以下操作

If you have already made some commits, you can do the following

git pull --rebase

这会将您所有的本地提交置于新拉取的更改之上.

This will place all your local commits on top of newly pulled changes.

要非常小心:这可能会用这些文件覆盖您当前的所有文件,因为它们位于远程存储库中分支的头部!如果发生这种情况并且您不希望发生这种情况,您可以使用

BE VERY CAREFUL WITH THIS: this will probably overwrite all your present files with the files as they are at the head of the branch in the remote repo! If this happens and you didn't want it to you can UNDO THIS CHANGE with

git rebase --abort 

...在进行任何新提交之前,您自然必须这样做!

... naturally you have to do that before doing any new commits!

这篇关于如何解决git错误:“更新被拒绝,因为您当前分支的提示落后"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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