解决git push报错
间隔了一段时间未往gitlab上push文件,近期使用时,发现push时报错,这里记录下解决处理的方法。
错误一:
1[root@361way shell]# git push
2warning: push.default is unset; its implicit value is changing in
3Git 2.0 from 'matching' to 'simple'. To squelch this message
4and maintain the current behavior after the default changes, use:
5 git config --global push.default matching
6To squelch this message and adopt the new behavior now, use:
7 git config --global push.default simple
8See 'git help config' and search for 'push.default' for further information.
9(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
10'current' instead of 'simple' if you sometimes use older versions of Git)
放”狗”查询后,得知‘matching’ 参数是 Git 1.x 的默认行为,其意是如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。而 Git 2.x 默认的是 simple,意味着执行 git push 没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码。键入如下命令:
1[root@361way shell]# git config --global push.default matching
错误二:
1[root@361way shell]# git push -u origin master
2To https://361way:[email protected]/361way/shell.git
3 ! [rejected] master -> master (fetch first)
4error: failed to push some refs to 'https://361way:[email protected]/361way/shell.git'
5hint: Updates were rejected because the remote contains work that you do
6hint: not have locally. This is usually caused by another repository pushing
7hint: to the same ref. You may want to first merge the remote changes (e.g.,
8hint: 'git pull') before pushing again.
9hint: See the 'Note about fast-forwards' in 'git push --help' for details.
再次push,发现又有报错,根据报错内容,大致了解的情况是,本地和远端的内容可能不一致,建议git pull 一份,再push到romte 。由于平时有些修改会在阿里云服务器上修改过的懒得push到远端同步,所以本地和远端的不一致也是有可能的。即然不一致,以阿里云上保存的为准吧,强制同步下。
1[root@361way shell]# git push -u origin master --force
强制同步,发现可以正常同步内容到github上,而且后面再加文件进行同步,发现也未出现报错了。
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/git-push-error/5604.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.