GitHub-git pushエラー解決

2347 ワード

GitHubを使用してコードpushを行うと、次のエラーが発生します.どうすればいいですか?
エラーの説明:
 ! [rejected]        master -> master (non-fast-forward)error: failed to push some refs to '[email protected]:Willido/First.git'To prevent you from losing history, non-fast-forward updates were rejectedMerge the remote changes (e.g. 'git pull') before pushing again.  See the'Note about fast-forwards'section of'git push--help'for details.エラーの原因:
gitウェアハウスにはすでにコードの一部があり、リモートウェアハウスのコードバージョンがローカルウェアハウスと一致しないため、コードを直接上書きすることはできません.
解決策:
1)押し付ける
強制アップロード、すなわちgit倉庫のコンテンツの代わりにローカルのコンテンツを強力なオーバーライド方式で使用し、コマンドは以下の通りです.
 
$ git push -f

 
2)ダウンロードしてからアップロードする
a.git倉庫の内容fetchをローカルにダウンロードしてからmergeし、コマンドは以下の通りです.
$ git fetch

$ git merge

直接pullすることもできます.コマンドは次のとおりです.
$ git pull

しかし、この場合、次のようなエラーメッセージが表示されます.
You asked me to pull without telling me which branch youwant to merge with, and 'branch.master.merge' inyour configuration file does not tell me, either. Pleasespecify which branch you want to use on the command line andtry again (e.g. 'git pull ').See git-pull(1) for details.If you often merge with the same branch, you may want touse something like the following in your configuration file:    [branch "master"]    remote =     merge =     [remote ""]    url =     fetch=See git-config(1)for details.上に登場する[branch"master"]は、以下の内容(.git/configにある)[branch"master")を明確にする必要がある    remote = origin
    merge = refs/heads/master
これはgitに2つのことを伝えます.
1.master branchにいる場合、デフォルトのremoteはoriginです.
2.master branchでgit pullを使用する場合、remoteとbranchを指定しない場合、gitはデフォルトのremote(すなわちorigin)を使用してmaster branch上のすべての変更をmergeします.
configファイルを手動で編集したり、端末でコマンドラインを編集したりすることができます.必要なコマンドラインは次のとおりです.
$ git config branch.master.remote origin  

$ git config branch.master.merge refs/heads/master

b.次にもう一度pullし直します.コマンドラインは次のとおりです.
$ git pull

c.最後にpushを行い、コマンドラインは以下の通りです.
$ git push