教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 bat脚本 git pull_Git遇到错误时如何解决的一些坑

bat脚本 git pull_Git遇到错误时如何解决的一些坑

发布时间:2022-01-07   编辑:jiaochengji.com
教程集为您提供bat脚本 git pull,Git遇到错误时如何解决的一些坑等资源,欢迎您收藏本站,我们将为您提供最新的bat脚本 git pull,Git遇到错误时如何解决的一些坑资源

在工作中,你总是与代码打交道,上传代码的时候,相信你不是用svn,就是用Git版本控制器,下面是最近这几天整理下来经常会遇到的Git的一些错误的解决访问,希望能帮助到你。

<h3>1 git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:</h3>

方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

<pre class="has"><code>git stash git pull origin master git stash pop </code></pre>

如此一来,服务器上的代码更新到了本地,而且你本地修改的代码也没有被覆盖,之后使用add,commit,push 命令即可更新本地代码到服务器了。

方法2、如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:

<pre class="has"><code>git reset --hard git pull origin master </code></pre>
<h3>2 在git push origin master时出现以下这个问题时:</h3>
<pre class="has"><code>error: failed to push some refs to 'git@github.com:yangchao0718/cocos2d.git hint: Updates were rejected because the tip of your current branch is behin hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. </code></pre>

出现错误的主要原因是github中的README.md文件不在本地代码目录中 可以通过如下命令进行代码合并【注:pull=fetch merge]

<pre class="has"><code>git pull --rebase origin master git push -u origin master </code></pre>
<h3>3 如果出现这样的错误:The file will have its original line endings in your working directory.</h3>

解决办法:

<pre class="has"><code>git rm -r --cached ./ git config core.autocrlf false git add ./ </code></pre>
<h3>4 git出现这样的错误:Git master branch has no upstream branch</h3>
<pre class="has"><code>$> git push fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master </code></pre>

原因分析:没有将本地的分支与远程仓库的分支进行关联。出现这种情况主要是由于远程仓库太多,且分支较多。在默认情况下,git push时一般会上传到origin下的master分支上,然而当repository和branch过多,而又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标。

解决: 方法一:(远程分支存在的情况才能使用)

<pre class="has"><code># 查看要指向的 repository git remote -v # 查看所有分支 git branch -a git push --set-upstream origin master # master: 远程branch # oringin: 在clone远程代码时,git为你创建的指向这个远程代码库的标签,它指向repository。 </code></pre>

方法二:根据需要,替换origin和master,此方法的好处是即使远程没有你要关联的分支,它也会自动创建一个出来,以实现关联。

<pre class="has"><code>git push -u origin master </code></pre>
<h3>5 出现这个错误:! [rejected] master -> master (fetch first)</h3>
<pre class="has"><code>! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@11.111.11.11:bboyHan/golang-data.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first 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. </code></pre>

原因分析:没有同步远程的master 解决:

<pre class="has"><code>git pull origin master </code></pre>
<h3>6 Git出现failed to push some refs to</h3>

描述:

<pre class="has"><code>$ git push -u origin master To git@github.com:******/Demo.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:******/Demo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. </code></pre>

解决方法:

<pre class="has"><code>(1).使用强制push的方法: $ git push -u origin master -f 这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。 (2).push前先将远程repository修改pull下来 $ git pull origin master $ git push -u origin master (3).若不想merge远程和本地修改,可以先创建新的分支: $ git branch [name] 然后push $ git push -u origin [name] </code></pre>
<h3>7 Git出现fatal: refusing to merge unrelated histories的时候</h3>

描述:这是从远程库pull项目,合并文件发生的异常

解决方案:在pull的时候添加 --allow-unrelated-histories。

<pre class="has"><code>$ git pull origin master ----allow-unrelated-histories </code></pre>

这个功能是可以让大家不要把仓库上传错了,如果会加上这个代码,那么就是自己确定了上传。之前很容易就把代码传错了,现在可以看到,如果上传的不是之前的,那么就需要加代码。

<h3>8 当Git出现error:src refspec master does not match any 错误时:</h3>

描述:在push项目的时候,引发该异常。 原因分析:目录中没有文件,空目录是不能提交上去的,获取没有add、commit文件直接进行push了。 解决方案:

<pre class="has"><code>touch README git add README git commit -m 'first commit' git push origin master </code></pre>
<h3>9 git时出现fatal: Authentication failed for '<span style="font-weight:bold;">https://</span><span style="font-weight:bold;">github.com/</span><span style="font-weight:bold;"/> ...</h3>

描述:使用的https提交,在用SourceTree提交代码时候发生错误,返回的错误提示说:fatal:Authentication failed for'https://github.com/... 解决方案:重新执行Git config命令配置用户名和邮箱即可:

<pre class="has"><code>git config -–global user.name "xxx" git config –-global user.email "xxx@xxx.com" </code></pre>

以上分支看自己的而定,这里都是以master为主

<blockquote> 以上内容希望帮助到大家,很多PHPer在进阶的时候总会遇到一些问题和瓶颈,业务代码写多了没有方向感,不知道该从那里入手去提升,对此我整理了一些资料,包括但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql优化、shell脚本、Docker、微服务、Nginx等多个知识点高级进阶干货需要的可以免费分享给大家 ,需要请戳这里链接 <i>或者</i>关注咱们下面的专栏 </blockquote> PHP大神进阶​zhuanlan.zhihu.com
到此这篇关于“bat脚本 git pull_Git遇到错误时如何解决的一些坑”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
bat脚本 git pull_Git遇到错误时如何解决的一些坑
如何正确理解PHP的错
ASP 3.0高级编程(三十一)
关于PHP Shell_exec所遇到的坑
xampp集成环境中php的date()函数获取时间错误的解决办法
python如何安装git
html5使用canvas压缩图片的示例代码
VBS脚本、BAT批处理删除自身的方法
在centos虚拟机上安装go语言开发环境
详解HTML5 录音遇到的坑

[关闭]
~ ~