git pull 表示最新但 git push 拒绝非快进
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4312059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git pull says up-to-date but git push rejects non-fast forward
提问by Jake
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.
我刚刚拉了一个新分支,做了一些本地更改,提交并尝试推送。我收到了这个错误:! [rejected] groups -> groups (non-fast forward)
所以我试图拉但被告知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?
任何人都可以解释这是如何发生的以及我如何解决它?
采纳答案by Benoit Courtine
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.
当你拉分支时,你是否使用了“--track”选项(为了让你的本地分支跟踪远程分支)。如果没有,它可以解释“合并”命令不起作用。
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:
注意:如果你想保留线性历史,而不是“合并”,你可以在推送之前在远程上对本地分支进行“rebase”:
git rebase origin/groups
git push origin groups
回答by dfrankow
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:
我的 git 设置为推送所有分支。我在一个分支 FOO 上,但它也在尝试推送 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:
我在我的 .gitconfig 中添加了以下内容,默认情况下只推送当前分支:
[push]
default = current
回答by garnet
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.
我的本地分支没有远程分支来从正确配置的 [git pull] 中提取更改。这从 的 o/p 很明显git remote show origin
。因此,我不得不使用git pull origin <branch_name>
而不是git pull
拉动更改。