git studyGit使用Git

git 入门系列(一)

2016-09-25  本文已影响113人  小Toubi

git学习-commit、push常见问题及解决措施(一)

git commit

当本地修改完分支,准备将暂存区的修改提交到本地仓库时,输入git commit,退出vi编辑界面(esc+shiftqenter),出现以下出错信息:

$ git commit
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

问题所在:
vi编辑器非正常退出时,会返回非零状态码。问题可能时由vi非正常退出有关。

解决办法:
接纳git的建议,直接使用git commit -m <msg>添加注释信息
如下列所示:

$ git commit -a -m "user's message"

提交成功。建议每次提交都注释信息,用于提醒自己或告诉合作伙伴每次提交所作的改变。

git push

git push有多种命令格式,当本地仓库的要推送的分支的名字与远程仓库分支的名字相同时: 采用git push origin branch_name,若本地仓库的要推送的分支的名字与远程仓库分支的名字不同时:采用git push origin <local_branch_name>:<remote_branch_name>
常见问题:

 ! [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'

原因:
第一个问题:远程代码与本地代码冲突
第二个问题:本地分支为空,需要提交后,才能push
解决办法
第一个问题:通过git pull 再手动或自动合并冲突后再push
第二个问题:git commit -m <message>后输入git push


git pull

常见问题:

$ 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

原因:
未指定本地分支与远程分支的关系
解决办法:
通过以下命令建立关系

$  git branch --set-upstream message origin/Toubi

即能执行pull操作,将远程Toubi分支拉取到本地分支message。

上一篇 下一篇

猜你喜欢

热点阅读