Git 推送抱怨非快进,即使远程已被拉取
我正在尝试将更改推送到 NAS 上的存储库。它以我不明白的方式失败了。
文档指出默认情况下< code>push 仅适用于快进更新。很公平。所以我做了一个 git pull
(我的遥控器称为 rubix
):
D:\RoboCup\Dev\TinMan>git pull rubix master From ssh://rubix/volume1/git/TinMan * branch master -> FETCH_HEAD Already up-to-date.
一切看起来都很好。让我们尝试推送...
D:\RoboCup\Dev\TinMan>git push rubix master To ssh://dnoakes@rubix/volume1/git/TinMan ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://dnoakes@rubix/volume1/git/TinMan' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
我已经阅读了 git push 上的文档,但此时我无法理解为什么会遇到这个问题。
这是其他一些上下文信息:
D:\RoboCup\Dev\TinMan>git --version git version 1.7.0.2.msysgit.0 D:\RoboCup\Dev\TinMan>git branch * (no branch) master
最后一行看起来很可疑。我怎么可能不在任何分支机构?另请注意,我还有一些未跟踪的文件和已修改(未暂存)的更改。
任何帮助将不胜感激。谢谢。
I'm trying to push my changes to a repo on my NAS. It's failing in a way I don't understand.
The documentation states that by default push
works only with fast-forward updates. Fair enough. So I do a git pull
(my remote is called rubix
):
D:\RoboCup\Dev\TinMan>git pull rubix master From ssh://rubix/volume1/git/TinMan * branch master -> FETCH_HEAD Already up-to-date.
All looks well. Let's try pushing...
D:\RoboCup\Dev\TinMan>git push rubix master To ssh://dnoakes@rubix/volume1/git/TinMan ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://dnoakes@rubix/volume1/git/TinMan' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
I've read through the documentation on git push
but at this point I can't understand why I'm seeing this problem.
Here is some other contextual info:
D:\RoboCup\Dev\TinMan>git --version git version 1.7.0.2.msysgit.0 D:\RoboCup\Dev\TinMan>git branch * (no branch) master
That last line looks suspect. How can I not be on any branch? Note too that I have some untracked files and modifieds (unstaged) changes too.
Any help would be greatly appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一种同步方法。
首先,提交任何更改,然后使用 git log 记录您想要推送的任何提交。
接下来重置您的主机以匹配遥控器,如下所示:
最后,挑选您想要保留的提交
示例:
现在推送应该可以工作。
Here's one way to get synced up.
First, Commit any changes, then use
git log
to note any commits you wanted to push.Next reset your master to match the remote like this:
Finally, cherry pick the commits you wanted to keep
Example:
Now pushing should work.
我不知道你是怎么最终没有分支的。您可能正处于变基过程中。您可能已经直接签出了提交。无论如何,这可能是导致你陷入困境的原因。检查
git reflog
以查看是否显示任何明显的原因,并检查git log
以查看您所在的位置。使用 git diff 查看已更改的文件,以决定是否要保留它们(如果需要,请使用 git add . && git stash )。然后,一旦您确定不需要任何更改或任何当前历史记录,git checkout master
即可返回。I'm not sure how you ended up on no branch. You may be in the middle of a rebase. You may have checked out a commit directly. In any event, this is likely the cause of your pushing woes. Check
git reflog
to see if it shows any obvious cause andgit log
to see where you are. Look at the changed files withgit diff
to decide if you want to keep them (and usegit add . && git stash
if you do). Then, once you are sure you don't need any changes or any of your current history,git checkout master
to get back.如果仍然不起作用,您可能需要配置 git 以接受别名分支名称
默认情况下,如果您的远程分支名称是 origin/master,则 git 仅在本地跟踪分支时接受您的推送名字是大师。如果您创建本地跟踪分支为 master_xxx,git 将不会接受您的推送,除非您将 push.default 配置修改为上游。
If it still not work, you may probably need to configure your git to accept alias branch name
By default, if your remote branch name is origin/master, git will only accept your push if your local tracking branch name is master. If you create a local tracking branch as master_xxx, git will not accept your push unless you modify your push.default configuration to upstream.
我遇到了同样的问题并遇到了这个问题,所以我想我会发布我的问题的解决方案。
注意:我在 Windows 上使用 git。
我不小心用不同的大小写检查了我的本地分支:“Develop”而不是我通常的“develop”。我所做的任何事情都无法纠正问题(即使在检查了具有正确大小写的分支之后),直到我按照以下步骤操作:
I had this same problem and came across this question, so I thought I would post the solution to my problem.
NOTE: I am using git on Windows.
I had accidentally checked out my local branch with different casing: "Develop" instead of my usual "develop." Nothing I did would correct the issue (even after checking out the branch with the correct casing) until I followed these steps: