今天在用git的时候遇到了一个问题。在想远程分支push的时候,出现了以下的错误:

! [remote rejected] master -> refs/for/master (change 144 closed)

error: failed to push some refs to ...

检查了一下发现是由于本地分支的版本号相比远程分支的版本号低。

解决的过程中有例如以下问题:

1、(不建议使用)直接在当前分支pull了一下,合并的时候发现有冲突,解决后commit --amend出错,大意是“合并中不能amend”。

2、新建了一个分支new用于保存当前的工作。回master分支,使用git reset --hard ****(****是commit_id前四位)命令回滚到之前的commit状态,保证这个commit节点在远程分支上,而不是本地的未push的commit。然后pull能够非常顺利的将本地master分支更新与远程分支一致。然后在合并new分支到master分支,这样就回到了1的情况,合并后不能amend。

(之所以用2的方法,是由于这样就有了一个备份,在合并的假设出现故障导致一些丢失也能够轻松找回。)

上面2个方法amend都会报错,可是新建一个commit的话就能顺利完毕合并。

事实上合并的过程中假设没有冲突会自己主动创建新的commit,自己主动加入的描写叙述是  merge branch ‘...’  。可是出现冲突的话就会停下来,由我们自己来解决冲突后,手动add->commit新建节点,这是默认的描写叙述还是是  merge branch ‘...’  。

之所以一直尝试amend是由于工作的须要。可是还没有一个好的解决方法,依据合并的原理来看应该是不可能去amend了。

可是git提供了第二种方式:衍合rebase。

在new分支下,git rebase master就能够进行衍合,衍合后在master分支最未端就会出现new分支下的commit,这样就能保证push的commit的changeid是不变的。

上面的衍合是基于没有冲突的情况的,有冲突的情况还待实验。

Git本地分支版本号过低导致的push错误 error: failed to push some refs to ... 及兴许amend的更多相关文章

  1. vue 项目上传到码云,push时error: failed to push some refs to 'https://gitee.com/mawenrou/vue_ht.git'

    vue 项目上传到码云,push时error: failed to push some refs to 'https://gitee.com/mawenrou/vue_ht.git' 因为之前已经创建 ...

  2. git 错误error: failed to push some refs to

    今天使用VSCODE 学习node.js,  想在git上push代码 于是在git上建立了一个私有的长裤, 连接后push代码时提示如下错误: error: failed to push some ...

  3. 解决git push出现error: failed to push some refs to 错误

    错误截图 背景 码云上创建了空项目 本地项目绑定了远程仓库,尝试git push,然后报了错 解决办法 使用强制命令git pull origin master --allow-unrelated-h ...

  4. 由于github仓库中提前建立readme文件,导致git push报错error: failed to push some refs to 'git@github.com:

    $ git push -u origin master To git@github.com:xxx/xxx.git ! [rejected] master -> master (fetch fi ...

  5. git rebase与 git合并(error: failed to push some refs to)解决方法

    1.遇到的问题 本地有一个git仓库,在github上新建了一个空的仓库,但是更新了REWADME.md的信息,即在github上多了一个提交. 关联远程仓库,操作顺序如下: git remote a ...

  6. git push origin master出错:error: failed to push some refs to

    1.输入git push origin master 出错:error: failed to push some refs to 那是因为本地没有update到最新版本的项目(git上有README. ...

  7. git push -u origin master error: failed to push some refs to

    1.问题描述 $ git push -u origin master To github.com:[github_name]/[github_repository_name].git ! [rejec ...

  8. git 解决 error: failed to push some refs to 'https://github.com/xxxx.git'

    在github远程创建仓库后, 利用gitbash进行提交本地文件的时候出现如下错误 [root@foundation38 demo]# git push -u origin master Usern ...

  9. git push 报错:failed to push some refs to 'git@git.xxxx:devops/thor.git'

    error: failed to push some refs to 'git@git.caicaivip.com:devops/thor.git' hint: Updates were reject ...

随机推荐

  1. Python3 官方文档翻译 - 5 数据结构

    这章会更详细地描述了一些你已经学过的知识,同时添加一些新东西. 5.1 List进阶 下面是关于List的所有方法 list.append(x) 将元素添加至列表尾,相当于a[len(a):] = [ ...

  2. android动画效果演示

    第一种:TranslateAnimation  动画效果演示: public void move(View view) { // 传统动画效果 TranslateAnimation animation ...

  3. for循环语句之棋盘放粮食、百鸡百钱、纸张的折叠问题

    1.棋盘放粮食 ; ; i < ; i++) { ; ; j <= i; j++) { x = x * ; } lszl = lszl + x; } double zl = lszl * ...

  4. ThinkPHP - Widget 工具

    提出问题:widget能实现什么功能? 显示右侧博文: 1.首先在Home目录下新建Widget文件夹,之后建立对应文件 2.拿最热Hot新闻来举例: 在Tpl目录下Common公共文件夹里的righ ...

  5. 修改字符串 ToCharArray()

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. [Swust OJ 322]--东6宿舍灵异事件(中缀表达式转化为后缀表达式的简单运用)

    题目链接:http://acm.swust.edu.cn/problem/322/ Time limit(ms): 1000 Memory limit(kb): 65535     Descripti ...

  7. listview 拖动item效果实现

    listview 拖动item效果实现 效果图如下: 拖拽前: 拖拽后: 首先参考源码中:TouchInterceptor 类,该类会在下面给出: 第一步:主类: /**  *   */ packag ...

  8. 浏览器与服务器间的交互(客服端 <---> 服务器)

    浏览器与服务器间的交互(客服端 <---> 服务器) 请求--->处理--->响应 对类HttpContext 内部成员的使用 例如 :Request .Response .  ...

  9. javascript时间函数

    //时间函数 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear();    //获取完 ...

  10. bash有空格的文件名

    http://www.keakon.net/2011/10/20/bash%E4%B8%8B%E5%A4%84%E7%90%86%E5%8C%85%E5%90%AB%E7%A9%BA%E6%A0%BC ...