问题描述
我最近开始使用Git(以前我使用过Subversion,但现在我正在做一些使用bitbucket和git的项目的协作工作)。
所有工作都一直在进行直到今天,当我发现一个善意的同事已经把改变推向了主而不是分支。这意味着,当我尝试提交时,我收到错误消息:
由于当前分支的提示位于
$ b之后$ b
我知道这应该解决我做一个拉请求重新同步的东西,但我不想失去我在本地做出的改变,我同样不想强制提交和消灭
什么是正确的方法让我合并变更而不丢失?
如果您已经提交了一些提交,您可以执行以下操作:
git pull --rebase
这会将所有本地提交置于新提取的更改之上。
请仔细阅读本文:这可能会覆盖所有现有文件,因为它们位于远程回购分支的头部!如果发生这种情况并且您不想要它,您可以 UNDO THIS CHANGE 与
git rebase --abort
...在做任何新的提交之前,你必须这么做!
I recently started using Git (previously I used subversion but I am now doing some collaborative work on a project that uses bitbucket and git).
All has been going well up until today when I find 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 my 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错误:“更新被拒绝,因为当前分支的提示位于”后面“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!