zoukankan      html  css  js  c++  java
  • Git冲突:commit your changes or stash them before you can merge

    Git冲突:commit your changes or stash them before you can merge

    在使用 git pull命令下拉远程分支代码时,报了 commit your changes or stash them before you can merge 这个错误。

    1、报错原因

    请先看报错截图:

    image-20210319142824053

    从报错提示可以知道,远程分支与本地分支修改了同一个文件,导致了 Git 冲突。在这个截图中,由于我本地修改了 application.properties文件,而远程分支上也同样修改了这个文件,导致无法 git pull

    2、解决方法

    思路:这个时候可以先把本地工作区的修改暂存到栈中,然后下拉远程分支代码,接着取出栈中的修改进行合并。

    • git stash命令把当前工作区和暂存区的改动保存到栈中,接着恢复本地分支为改动前的分支,通过 git status可以查看分支状态。
    • 此时执行git pull便能够下拉远程分支代码。
    • 执行 git stash pop取回保存在栈中的本地分支的修改,最后解决冲突。

    因此,需要执行的命令行如下:

    # 保存当前工作区和暂存区的改动到栈中
    git stash
    # 获得远程分支代码
    git pull
    # 恢复栈中最新的工作区和暂存区的改动到工作区,并删除栈中信息
    git stash pop
    

    3、stash其他常用命令

    # 获取堆栈列表
    git stash list
    
    # 恢复最新的进度到工作区和暂存区。(尝试将原来暂存区的改动还恢复到暂存区)
    git stash pop --index
    
    # 恢复指定的进度到工作区,删除栈中信息
    git stash pop stash@{1}
    
    # 恢复指定的进度到工作区,不删除栈中信息
    git stash apply stash@{1}
    
    # 清空堆栈列表
    git stash clear
    
    # 删除指定的栈中信息
    git stash drop stash@{1}
    
    自我控制是最强者的本能-萧伯纳
  • 相关阅读:
    人机博弈,吃子棋游戏(一)基本介绍
    cesm下载备注
    mysql数据库批量高速插入
    持续学习
    顺序表的功能实现
    Broccoli & Babel使用演示样例
    rk3188调试记录
    Operation not allowed on a unidirectional dataset错误?
    dbExpress操作中用TDBGrid显示数据
    dbexpress连接mysql提示Operation not allowed on a unidirectional dataset
  • 原文地址:https://www.cnblogs.com/CF1314/p/14591004.html
Copyright © 2011-2022 走看看