Git push 拒绝“非快进”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20467179/
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 push rejected "non-fast-forward"
提问by Frankline
I am fairly new to git
yet currently using it to manage our code in a team environment. I had some rebasing issues and I fixed them using
我对git
目前使用它在团队环境中管理我们的代码还很陌生。我有一些变基问题,我使用
git checkout --ours filename.txt
git add filename.txt
git rebase --continue
Now I wish to push my changes, and so running the following command
现在我希望推送我的更改,因此运行以下命令
$ git push origin feature/my_feature_branch
gives me the following error:
给了我以下错误:
To ssh://[email protected]:7999/repo/myproject.git
! [rejected] feature/my_feature_branch -> feature/my_feature_branch (non-fast-forward)
error: failed to push some refs to 'ssh://[email protected]:7999/repo/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
What can I do to get rid of the error?
我该怎么做才能摆脱错误?
P.S. : I am avoiding to use the --force
option as much as possible.
PS:我--force
尽量避免使用该选项。
采纳答案by Boris Brodski
It looks, that someone pushed new commits between your last git fetch
and git push
. In this case you need to repeat your steps and rebase my_feature_branch
one more time.
看起来,有人在你的最后一次git fetch
和git push
. 在这种情况下,您需要重复您的步骤并my_feature_branch
再重新设定一次基准。
git fetch
git rebase feature/my_feature_branch
git push origin feature/my_feature_branch
After the git fetch
I recommend to examine situation with gitk --all
.
在git fetch
我建议使用gitk --all
.
回答by Engineer
Probably you did not fetch the remote changes before the rebase or someone pushed new changes (while you were rebasing and trying to push). Try these steps:
可能您在 rebase 之前没有获取远程更改,或者有人推送了新的更改(当您正在 rebase 并尝试推送时)。尝试以下步骤:
#fetching remote 'feature/my_feature_branch' branch to the 'tmp' local branch
git fetch origin feature/my_feature_branch:tmp
#rebasing on local 'tmp' branch
git rebase tmp
#pushing local changes to the remote
git push origin HEAD:feature/my_feature_branch
#removing temporary created 'tmp' branch
git branch -D tmp
回答by Aurelio A
I had this problem! I tried: git fetch + git merge, but dont resolved! I tried: git pull, and also dont resolved
我有这个问题!我试过:git fetch + git merge,但没有解决!我试过:git pull,也没有解决
Then I tried this and resolved my problem (is similar of answer of Engineer):
然后我尝试了这个并解决了我的问题(类似于工程师的回答):
git fetch origin master:tmp
git rebase tmp
git push origin HEAD:master
git branch -D tmp
回答by William Rossier
I had a similar problem and I resolved it with:
git pull origin
我有一个类似的问题,我解决了它:
git pull origin
回答by Bilal
I'm late to the party but I found some useful instructions in github help pageand I wanted to share them here.
我迟到了,但我在github 帮助页面中找到了一些有用的说明,我想在这里分享它们。
Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.
有时,Git 无法在不丢失提交的情况下对远程存储库进行更改。发生这种情况时,您的推送将被拒绝。
If another person has pushed to the same branch as you, Git won't be able to push your changes:
如果其他人已推送到与您相同的分支,Git 将无法推送您的更改:
$ git push origin master
To https://github.com/USERNAME/REPOSITORY.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:
您可以通过获取远程分支上所做的更改并将其与您在本地所做的更改合并来解决此问题:
$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work
Or, you can simply use git pull
to perform both commands at once:
或者,您可以简单地用于git pull
同时执行两个命令:
$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work
回答by Boris Zinchenko
Write lock on shared local repository
共享本地存储库上的写锁
I had this problem and none of above advises helped me. I was able to fetch everything correctly. But push always failed. It was a local repository located on windows directory with several clients working with it through VMWare shared folder driver. It appeared that one of the systems locked Git repository for writing. After stopping relevant VMWare system, which caused the lock everything repaired immediately. It was almost impossible to figure out, which system causes the error, so I had to stop them one by one until succeeded.
我遇到了这个问题,以上建议都没有帮助我。我能够正确获取所有内容。但是推送总是失败。它是一个位于 windows 目录中的本地存储库,多个客户端通过 VMWare 共享文件夹驱动程序使用它。似乎其中一个系统锁定了 Git 存储库以进行写入。停止相关的VMWare系统后,导致锁定一切立即修复。几乎无法弄清楚是哪个系统导致了错误,所以我不得不一一阻止,直到成功。
回答by Mike Q
Well I used the advice here and it screwed me as it merged my local code directly to master. .... so take it all with a grain of salt. My coworker said the following helped resolve the issue, needed to repoint my branch.
好吧,我在这里使用了建议,它把我搞砸了,因为它将我的本地代码直接合并到 master。......所以用一粒盐把这一切都带走。我的同事说以下帮助解决了这个问题,需要重新指向我的分支。
git branch --set-upstream-to=origin/feature/my-current-branch feature/my-current-branch
回答by MansoorShaikh
In Eclipse do the following:
在 Eclipse 中执行以下操作:
GIT Repositories > Remotes > Origin > Right click and say fetch
GIT Repositories > Remotes > Origin > 右键单击并说 fetch
GIT Repositories > Remote Tracking > Select your branch and say merge
GIT 存储库 > 远程跟踪 > 选择您的分支并说合并
Go to project, right click on your file and say Fetch from upstream.
转到项目,右键单击您的文件并说从上游获取。
回答by richard
- move the code to a new branch - git branch -b tmp_branchyouwantmergedin
- change to the branch you want to merge to - git checkout mycoolbranch
- reset the branch you want to merge to - git branch reset --hard HEAD
- merge the tmp branch into the desired branch - git branch merge tmp_branchyouwantmergedin
- push to origin
- 将代码移动到新分支 - git branch -b tmp_branchyouwantmergedin
- 更改到要合并到的分支 - git checkout mycoolbranch
- 重置要合并到的分支 - git branch reset --hard HEAD
- 将 tmp 分支合并到所需的分支 - git branch merge tmp_branchyouwantmergedin
- 推到原点
回答by ivever timothy
try this command
试试这个命令
$ git push -f -u origin <name of branch>
$ git push -f -u origin <name of branch>
i.e $ git push -f -u origin master
IE $ git push -f -u origin master