我正在尝试推送我的项目(所有文件都在新的存储库中).我按照步骤操作,但当我推进时,git push -u origin master
我收到此错误:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:asantoya/projectnewbies.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.
Run Code Online (Sandbox Code Playgroud)
很多次我得到这个错误,无法弄清楚该怎么做.
小智 150
试试这个: git push -f origin master
pmr*_*pmr 145
正如错误消息所示:git pull
在您尝试之前git push
.显然,您的本地分支与跟踪分支不同步.
根据项目规则和您可能还想使用的工作流程git pull --rebase
.
小智 19
git push -f origin master
Run Code Online (Sandbox Code Playgroud)
使用蛮力 ;-) 很可能您正在尝试添加在 git 上创建 repo 之前创建的本地文件夹。
小智 18
这个命令对我很有用
git push -f origin master
Run Code Online (Sandbox Code Playgroud)
blu*_*sky 13
我刚收到这个错误.
我在创建了我的本地git存储库之后创建了一个github存储库,因此我需要在推送到github之前接受对本地的更改.在这种情况下,唯一的变化是在创建github存储库时作为可选步骤创建的自述文件.
git pull https://github.com/*username*/*repository*.git master
Run Code Online (Sandbox Code Playgroud)
存储库URL是从项目github页面获取的:
然后我重新初始化(可能不需要)
git init
git add .
git commit -m "update"
Run Code Online (Sandbox Code Playgroud)
然后推:
git push
Run Code Online (Sandbox Code Playgroud)
mah*_*mnj 11
我的遥控器与本地不同步,所以这对我有用
git pull --rebase
Run Code Online (Sandbox Code Playgroud)
并确保当您git pull
再次执行此操作时,它应该显示已经是最新的,现在您已准备好推送到原点
假设你已经git remote add origin remote repository URL
做
git push origin master
Run Code Online (Sandbox Code Playgroud)
我在github上创建了新的repo并且我遇到了同样的问题,但它在拉动时也有问题,所以这对我有用.
但是在repos中不建议这已经有很多代码,因为这可能会弄乱一切
git push origin master --force
Run Code Online (Sandbox Code Playgroud)
警告:
去'git pull'并不总是一个解决方案.如果您故意更改了存储库历史记录,则可能会遇到此问题(Q中提到的问题).在这种情况下,git会将您的历史记录更改与远程仓库中的新更改混淆.所以,你应该去找一个git pull
,因为打电话git push --force
会故意撤消你对你的历史所做的所有改变.
如果git pull
没有帮助,那么可能您已经推动了您的更改(A),之后曾经git commit --amend
添加了一些更改(B).因此,git认为您可以丢失历史记录 - 它将B解释为不同的提交,尽管它包含来自A的所有更改.
B
/
---X---A
Run Code Online (Sandbox Code Playgroud)
如果之后没有人改变回购A
,那么你就可以做到git push --force
.
但是,如果A
其他人之后发生了变化:
B
/
---X---A---C
Run Code Online (Sandbox Code Playgroud)
那么你必须从衍合那些人改变A
对B
(C
- > D
).
B---D
/
---X---A---C
Run Code Online (Sandbox Code Playgroud)
或手动修复问题.我还没想到怎么做.
小智 6
使用此命令:
git pull --allow-unrelated-histories <nick name of repository> <branch name>
喜欢:
git pull --allow-unrelated-histories origin master
当项目没有任何共同祖先时,会发生此错误。
小智 5
尝试以下命令:“ git pull origin master”
它为我工作。
检查此链接:https : //help.github.com/articles/dealing-with-non-fast-forward-errors
这是因为您在母版中做了一些更改,所以项目要求您先拉。如果仍要推动它,可以通过输入以下命令使用蛮力:
git push -f origin master
Run Code Online (Sandbox Code Playgroud)
切记先提交您的更改:
git add .
git commit -m "Your commit message"
Run Code Online (Sandbox Code Playgroud)