[英]How to resolve git error: "Updates were rejected because the tip of your current branch is behind"
A well meaning colleague has pushed changes to the Master instead of making a branch.一位好心的同事将更改推送给 Master 而不是创建分支。 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如果发生这种情况并且您不希望它发生,您可以使用UNDO THIS CHANGE
git rebase --abort
... naturally you have to do that before doing any new commits! ......自然你必须在做任何新的提交之前这样做!
I would do it this this way:我会这样做:
Stage all unstaged changes.暂存所有未暂存的更改。
git add .
Stash the changes.隐藏更改。
git stash save
Sync with remote.与遥控器同步。
git pull -r
Reapply the local changes.重新应用本地更改。
git stash pop
or或者
git stash apply
I had the exact same issue on my branch(lets call it branch B) and I followed three simple steps to get make it work我在我的分支上遇到了完全相同的问题(我们称之为分支 B),我按照三个简单的步骤让它工作
Now you can delete branch B and then rename branch C to branch B.现在您可以删除分支 B,然后将分支 C 重命名为分支 B。
Hope this helps.希望这可以帮助。
This worked for me:这对我有用:
git pull origin $(git branch --show-current)
git push
fyi git branch --show-current
returns the name of the current branch.仅供参考git branch --show-current
返回当前分支的名称。
I had the same problem.我有同样的问题。 Unfortunately I was in wrong catalog level.不幸的是,我的目录级别错误。
I tried to: git push -u origin master
-> there was a error我试图: git push -u origin master
-> 出现错误
Then I tried: git pull --rebase
-> there still was a problem然后我试了: git pull --rebase
-> 还是有问题
Finally i change directory cd your_directory
最后我改变目录cd your_directory
Then I tried again ( git push
) and it works!然后我再次尝试( git push
)并且它有效!
This issue occurs when someone has commited the code to develop/master and latest code has not been rebased from develop/master and you're trying to overwrite new changes to develop/master branch当有人将代码提交到开发/主控并且最新代码尚未从开发/主控重新定位并且您试图覆盖对开发/主控分支的新更改时,会出现此问题
Solution:解决方案:
I was able to overcome this issue with the following Visual Studio 2017 change:通过以下 Visual Studio 2017 更改,我能够克服此问题:
See: https://docs.microsoft.com/en-us/vsts/git/concepts/git-config?view=vsts&tabs=visual-studio#rebase-local-branch-when-pulling请参阅: https ://docs.microsoft.com/en-us/vsts/git/concepts/git-config?view=vsts&tabs=visual-studio#rebase-local-branch-when-pulling
I have used我用过
git push origin master
After update refusing, I looked up at a history:更新拒绝后,我查看了一个历史记录:
git log --oneline --all
My HEAD -> master was above origin/master.我的 HEAD -> master 高于 origin/master。
But I used forcing, and it was sufficient:但是我使用了强制,这就足够了:
git push --force-with-lease origin master
And the heads are together again...头颅又聚在一起了……
You are not currently on a branch.您当前不在分支上。 To push the history leading to the current (detached HEAD) state now, use要将历史推送到当前(分离的 HEAD)状态,请使用
git push origin HEAD:<name-of-remote-branch>
I had the same issue.我遇到过同样的问题。
Fix: git pull origin {branch-name}
sorted all.修复: git pull origin {branch-name}
全部排序。
Ref: There is no tracking information for the current branch参考: 当前分支没有跟踪信息
This worked for me and i will recommend it to you.这对我有用,我会推荐给你。 if you are on the local branch that you have commited, try renaming the branch with this git command如果您在已提交的本地分支上,请尝试使用此 git 命令重命名分支
git branch -m <new_name>
then push again with然后再次推动
git push --set-upstream origin <new_name>
I had this issue and I realized that .gitignore file is changed.我遇到了这个问题,我意识到 .gitignore 文件已更改。 So, I changed .gitignore and I could pull the changes.所以,我改变了 .gitignore 并且我可以拉动这些改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.