Git 推送抱怨非快进,即使远程已被拉取

发布于 2024-11-02 09:01:38 字数 1196 浏览 5 评论 0原文

我正在尝试将更改推送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

在梵高的星空下 2024-11-09 09:01:38

这是一种同步方法。

首先,提交任何更改,然后使用 git log 记录您想要推送的任何提交。

接下来重置您的主机以匹配遥控器,如下所示:

git checkout master
git reset --hard remotes/rubix/master 

最后,挑选您想要保留的提交

示例:

git cherry-pick 111aaa111
git cherry-pick 123abc123

现在推送应该可以工作。

git push rubix master

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:

git checkout master
git reset --hard remotes/rubix/master 

Finally, cherry pick the commits you wanted to keep

Example:

git cherry-pick 111aaa111
git cherry-pick 123abc123

Now pushing should work.

git push rubix master
吻风 2024-11-09 09:01:38

我不知道你是怎么最终没有分支的。您可能正处于变基过程中。您可能已经直接签出了提交。无论如何,这可能是导致你陷入困境的原因。检查 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 and git log to see where you are. Look at the changed files with git diff to decide if you want to keep them (and use git 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.

妞丶爷亲个 2024-11-09 09:01:38

如果仍然不起作用,您可能需要配置 git 以接受别名分支名称

git config --global push.default upstream

默认情况下,如果您的远程分支名称是 origin/master,则 git 仅在本地跟踪分支时接受您的推送名字是大师。如果您创建本地跟踪分支为 ma​​ster_xxx,git 将不会接受您的推送,除非您将 push.default 配置修改为上游

If it still not work, you may probably need to configure your git to accept alias branch name

git config --global push.default upstream

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.

凹づ凸ル 2024-11-09 09:01:38

我遇到了同样的问题并遇到了这个问题,所以我想我会发布我的问题的解决方案。

注意:我在 Windows 上使用 git。

我不小心用不同的大小写检查了我的本地分支:“Develop”而不是我通常的“develop”。我所做的任何事情都无法纠正问题(即使在检查了具有正确大小写的分支之后),直到我按照以下步骤操作:

  1. 签出具有正确大小写的分支“develop”
  2. 进行任何更改,添加/提交
  3. 现在您可以推送而不会被拒绝

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:

  1. Checkout out the branch with the correct casing "develop"
  2. Make any change, add/commit
  3. Now you can push without being rejected
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文