git远程分支的管理和git push错误汇总
摘要:使用git的时候多是在本地,而git远程分支的管理比较麻烦。在git使用的过程中,出现错误最多的命令大概是git push以后出现各种错误提示。本文主要解释git远程分支的基本运作原理,并总结git push出现的各种错误和解决方法。本文来源:git远程分支的管理与git push错误汇总
1.与远程有关的配置
git fetch origin:
解释: Fetches named heads or tags from one or more other repositories, along with the objects necessary to complete them.
The ref names and their object names of fetched refs are stored in .git/FETCH_HEAD. This information is left for a later merge operation done by git merge.
说明:从指定的ref取得git分支,其中.git/FETCH_HEAD指明了分支的来源。
git merge:
解释:Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.
明白git merge的来源:git merge nameOfbranch ,它是将指定的commit 或者tag merge到当前分支,但是它只是改变了工作目录的文件,并没有改变index和本地仓库。
git pull
Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.
More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs gitrebase instead of git merge.
这个命令等于git fetch和git merge FETCH_HEAD以后的结果。
2.git push常见错误汇总
2.1错误一:
error: failed to push some refs to 'git@github.com:rickyfeng/wenda.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.
出错原因:出现non-fast-forward ,往往是因为这样的情况:原来的提交记录是1.2-------1.3---------1.4,我们将1.4clone下来开发,同时别人也将1.4clone下来开发,然后别人先于我们而提交,产生了1.5版本:1.2------1.3------1.4------1.5,此时我们将修改过户的1.4版本提交到1.4版本上,必然会丢掉1.5这个记录,为了避免这种情况,我们在提交代码之前,先要进行pull
解决方法:pull,merge之后在push
补充:综合编程 , 其他综合 ,