[英]Source Tree Push : hint: Updates were rejected because the tip of your current branch is behind
I am trying to push my application with Source Tree.我正在尝试使用 Source Tree 推送我的应用程序。
I reverted the application (locally) to an old version, made some changes and now I want to push again, but I'm getting this error:我将应用程序(本地)恢复到旧版本,进行了一些更改,现在我想再次推送,但出现此错误:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags --set-upstream origin dev:dev
Pushing to https://user@bitbucket.org/hykaruz/assist-ponto.git
To https://user@bitbucket.org/hykaruz/project.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'https:/User:bitbucket.org/hykaruz/Project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
PS.附注。 My version was too old, I had to download the last version then I can commit and push my application, so if you get the same problem check to see if there's an update.我的版本太旧了,我必须下载最后一个版本,然后我才能提交和推送我的应用程序,所以如果你遇到同样的问题,请检查是否有更新。
In my case for exact same error, I was not the only developer.在我遇到完全相同的错误的情况下,我不是唯一的开发人员。
So I went to commit & push my changes at same time, seen at bottom of the Commit
dialog popup:所以我去提交并同时推送我的更改,在Commit
对话框弹出的底部看到:
...but I made the huge mistake of forgetting to hit the Fetch
button to see if I have latest, which I did not. ...但我犯了一个巨大的错误,忘记点击“ Fetch
按钮来查看我是否有最新的,而我没有。
The commit successfully executed, however not the push, but instead gives the same mentioned error;提交成功执行,但不是推送,而是给出了同样提到的错误; ...even though other developers didn't alter same files as me, I cannot pull latest as same error is presented. ...即使其他开发人员没有更改与我相同的文件,我也无法提取最新的文件,因为出现了相同的错误。
Most of the time I prefer sticking with Sourcetree's GUI (Graphical User Interface) .大多数时候我更喜欢坚持使用 Sourcetree 的GUI(图形用户界面) 。 This solution might not be ideal, however this is what got things going again for me without worrying that I may lose my changes or compromise more recent updates from other developers.这个解决方案可能并不理想,但是这让我重新开始工作,而不必担心我可能会丢失我的更改或损害其他开发人员的最新更新。
Right-click on the commit right before yours to undo your locally committed changes and select Reset current branch to this commit
like so:右键单击您之前的提交以撤消本地提交的更改,然后选择将Reset current branch to this commit
如下所示:
Once all the loading spinners disappear and Sourcetree is done loading the previous commit, at the top-left of window, click on Pull
button...一旦所有加载微调器消失并且 Sourcetree 完成加载前一个提交,在窗口的左上角,单击“ Pull
按钮...
...then a dialog popup will appear, and click the OK
button at bottom-right: ...然后将出现一个对话框弹出窗口,然后单击右下角的OK
按钮:
After pulling latest, if you do not get any errors, skip to STEP 4 (next step below).拉最新后,如果您没有收到任何错误,请跳到第4步(下面的下一步)。 Otherwise if you discover any merge conflicts at this point, like I did with my Web.config
file:否则,如果您此时发现任何合并冲突,就像我对Web.config
文件所做的那样:
...then click on the Stash
button at the top, a dialog popup will appear and you will need to write a Descriptive-name-of-your-changes, then click the OK
button: ...然后单击顶部的Stash
按钮,将出现一个对话框弹出窗口,您需要编写一个 Descriptive-name-of-your-changes,然后单击OK
按钮:
...once Sourcetree is done stashing your altered file(s), repeat actions in STEP 2 (previous step above), and then your local files will have latest changes. ...一旦 Sourcetree 完成存储更改的文件,请重复步骤 2 中的操作(上面的上一步),然后您的本地文件将具有最新更改。 Now your changes can be reapplied by opening your STASHES
seen at bottom of Sourcetree left column, use the arrow to expand your stashes, then right-click to choose Apply Stash 'Descriptive-name-of-your-changes'
, and after select OK
button in dialog popup that appears:现在可以通过打开在STASHES
底部看到的 STASHES 来重新应用您的更改,使用箭头展开您的Apply Stash 'Descriptive-name-of-your-changes'
,然后右键单击以选择Apply Stash 'Descriptive-name-of-your-changes'
,然后选择OK
出现的对话框弹出窗口中的按钮:
IF you have any Merge Conflict(s) right now, go to your preferred text-editor, like Visual Studio Code, and in the affected files select the Accept Incoming Change
link, then save:如果您现在有任何合并冲突,请转到您首选的文本编辑器,如 Visual Studio Code,并在受影响的文件中选择Accept Incoming Change
链接,然后保存:
Then back to Sourcetree, click on the Commit
button at top:然后回到 Sourcetree,点击顶部的Commit
按钮:
then right-click on the conflicted file(s), and under Resolve Conflicts
select the Mark Resolved
option:然后右键单击冲突的文件,并在Resolve Conflicts
选择Mark Resolved
选项:
Finally!!!终于!!! We are now able to commit our file(s), also checkmark the Push changes immediately to origin
option before clicking the Commit
button:我们现在可以提交我们的文件,并且在单击Commit
按钮之前选中Push changes immediately to origin
选项:
PS while writing this, a commit was submitted by another developer right before I got to commit, so had to pretty much repeat steps. PS 在写这篇文章时,另一个开发人员在我提交之前提交了一个提交,所以不得不重复步骤。
Because your commit history diverges from the upstream repository (you didn't just add more commits), git refuses to push the changes because you can lose work this way .因为您的提交历史与上游存储库不同(您不仅添加了更多提交),所以 git 拒绝推送更改,因为这样您可能会丢失工作。
If you are sure you want to overwrite the upstream repository history with your own (eg, you are the only one pushing to that repository), you have to add -f
to force the push.如果您确定要用自己的历史记录覆盖上游存储库历史记录(例如,您是唯一一个推送到该存储库的人),则必须添加-f
以强制推送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.