Far*_*oko 5 git version-control push github
当我键入git push origin master
以下错误消息从git显示:
To https://github.com/farrasdoko/RumahSakit.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/farrasdoko/RumahSakit.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
然后,i型git fetch origin
,git merge origin master
&git pull origin master
从GIT中所示的下面的错误消息:
From https://github.com/farrasdoko/RumahSakit
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Run Code Online (Sandbox Code Playgroud)
如何推?
hint: Updates were rejected because the tip of your current branch is behind
通常,当发生这种情况时,您真正想做的是在您自己的提交之前origin/master
将额外的提交添加到您的分支中。您可以使用以下命令来执行此操作:rebase
git rebase origin/master
Run Code Online (Sandbox Code Playgroud)
这将从您的分支中提取新的提交origin
,然后在顶部添加您自己的新提交,以便您的提交是最新的。变基时您可能会遇到一些冲突。当这种情况发生时,git
会停下来并告诉你解决冲突;之后,您应该受git add
影响的文件,然后git rebase --continue
. 或者,如果您决定不知道如何处理该问题,您可以git rebase --abort
并且您的分支将返回到命令启动之前的相同状态git rebase
。
git rebase
是一个强大的命令,可以让你的分支很快变得混乱,所以要小心它,但不要害怕它。标准计算建议适用:如果您没有信心,请在执行任何操作之前备份您的工作。幸运的是,很容易创建一个新分支作为备份 ( git checkout -b my_backup_branch
),然后切换回您的工作分支。