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


总结中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值