git pull 说是最新的,但 git push 拒绝非快进

发布于 2024-10-05 21:37:54 字数 407 浏览 12 评论 0原文

我刚刚拉了一个新分支,做了一些本地更改,承诺并尝试推动。我收到此错误:! [拒绝]组->组(非快进) 所以我尝试拉,但被告知已经是最新的。

这是我拉然后推的内容。

~/dev$ git pull origin groups
Already up-to-date.
~/dev$ git push origin groups
To /mnt/ebs/git/repo.git
 ! [rejected]        groups -> groups (non-fast forward)
error: failed to push some refs to '/mnt/ebs/git/repo.git'

谁能解释一下这是如何发生的以及我该如何解决它?

I've just pulled a new branch, made some local changes, committed and tried to push. I was given this error: ! [rejected] groups -> groups (non-fast forward)
So I tried a to pull but was told Already up-to-date.

Here's what I get pulling then pushing.

~/dev$ git pull origin groups
Already up-to-date.
~/dev$ git push origin groups
To /mnt/ebs/git/repo.git
 ! [rejected]        groups -> groups (non-fast forward)
error: failed to push some refs to '/mnt/ebs/git/repo.git'

Can anyone explain how this can be happening and how I can fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

久夏青 2024-10-12 21:37:55

我带着不同的问题来到这里。

我的 git 被设置为推送所有分支。我在 FOO 分支上,但它也在尝试推送 master,但它不是最新的。诀窍是注意到它正在尝试推送 master:

To [email protected]:repo
 ! [rejected]        master -> master (non-fast-forward)

我将以下内容添加到我的 .gitconfig 中,默认情况下仅推送当前分支:

[push]
    default = current

I came here with a different problem.

My git was set up to push all branches. I was on a branch FOO, but it was also trying to push master, which was not up to date. The trick was noticing it was trying to push master:

To [email protected]:repo
 ! [rejected]        master -> master (non-fast-forward)

I added the following to my .gitconfig to only push the current branch by default:

[push]
    default = current
残龙傲雪 2024-10-12 21:37:55

这不是所提问题的答案。我遇到了相同错误消息的不同问题。

我的本地分支没有远程分支来从正确配置的 [git pull] 中提取更改。这从 git remote show origin 的 o/p 中可以明显看出。因此,我必须使用 git pull origin而不是 git pull 来拉取更改。

This is not an answer to the question asked. I had a different problem with the same error message.

My local branch did not have the remote branch to pull the changes from configured properly [git pull]. This was evident from the o/p of git remote show origin. So, I had to use git pull origin <branch_name> instead of git pull to pull the changes.

双马尾 2024-10-12 21:37:54

当您拉取分支时,您是否使用了“--track”选项(为了让本地分支跟踪远程分支)。如果没有,则可以解释“合并”命令不起作用。

您可以手动进行合并:

git fetch
git merge origin/groups

要比较本地和远程存储库,我建议您使用此命令(将其添加到别名中,很有用):

git log --graph --oneline --all --decorate

它将打印项目历史记录树,显示分支标签。所以你会看到你的分支和原始分支的分歧点。

注意:如果您想保留线性历史记录,而不是“合并”,您可以在推送之前在远程上对本地分支进行“变基”:

git rebase origin/groups
git push origin groups

When you pulled the branch, did you use the "--track" option (in order to keep you local branch tracking the remote branch). If you did not, it can explain that the "merge" command that does not work.

You can do the merge manually:

git fetch
git merge origin/groups

To compare local and remote repos, I suggest you this command (add it in an alias, it is usefull):

git log --graph --oneline --all --decorate

It will print the project history tree, showing the branch labels. So you will see where your branch and the origin branch diverge.

Note: if you want to preserve a linear history, instead of a "merge", you can do a "rebase" of your local branch on the remote before pushing:

git rebase origin/groups
git push origin groups
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文