git學(xué)習(xí)-commit瓷炮、push常見(jiàn)問(wèn)題及解決措施(一)
git commit
當(dāng)本地修改完分支泪漂,準(zhǔn)備將暫存區(qū)的修改提交到本地倉(cāng)庫(kù)時(shí)咧七,輸入git commit
衰齐,退出vi編輯界面(esc
+shift
+q
+enter
),出現(xiàn)以下出錯(cuò)信息:
$ git commit
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.
問(wèn)題所在:
vi編輯器非正常退出時(shí)继阻,會(huì)返回非零狀態(tài)碼耻涛。問(wèn)題可能時(shí)由vi非正常退出有關(guān)。
解決辦法:
接納git的建議瘟檩,直接使用git commit -m <msg>
添加注釋信息
如下列所示:
$ git commit -a -m "user's message"
提交成功抹缕。建議每次提交都注釋信息,用于提醒自己或告訴合作伙伴每次提交所作的改變墨辛。
git push
git push
有多種命令格式歉嗓,當(dāng)本地倉(cāng)庫(kù)的要推送的分支的名字與遠(yuǎn)程倉(cāng)庫(kù)分支的名字相同時(shí): 采用git push origin branch_name
,若本地倉(cāng)庫(kù)的要推送的分支的名字與遠(yuǎn)程倉(cāng)庫(kù)分支的名字不同時(shí):采用git push origin <local_branch_name>:<remote_branch_name>
常見(jiàn)問(wèn)題:
! [rejected] message -> Toubi(non-fast-forward)
error: failed to push some refs to 'git@github.com:scut-Sherlock-H/Lutu.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
error: src refspec Toubi does not match any.
error: failed to push some refs to 'git@github.com:scut-Sherlock-H/Lutu.git'
原因:
第一個(gè)問(wèn)題:遠(yuǎn)程代碼與本地代碼沖突
第二個(gè)問(wèn)題:本地分支為空,需要提交后背蟆,才能push
解決辦法
第一個(gè)問(wèn)題:通過(guò)git pull
再手動(dòng)或自動(dòng)合并沖突后再push
第二個(gè)問(wèn)題:git commit -m <message>
后輸入git push
git pull
常見(jiàn)問(wèn)題:
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> message
原因:
未指定本地分支與遠(yuǎn)程分支的關(guān)系
解決辦法:
通過(guò)以下命令建立關(guān)系
$ git branch --set-upstream message origin/Toubi
即能執(zhí)行pull操作鉴分,將遠(yuǎn)程Toubi分支拉取到本地分支message。