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

    技术2025-01-12  19

    今天pull代码的时候发现pull有冲突,提示信息如下:

    善用搜索后发现有如下解决办法:

    通常遇到这个问题,可以直接commit自己的修改;

    1.stash

    看看git stash是如何做的

    git stash git pull git stash pop

    git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。git stash pop: 从Git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个Stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。git stash list: 显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现,原来stash的哪些节点都消失了。

    整个过程如下:

    git status . git pull // 出现该提示 Please, commit your changes or stash them before you can merge. git stash git pull git stash pop git status . git add . git commit -m "" git push

    2.放弃本地修改,直接覆盖之

    (慎用,本地修改会清除掉)

    git reset --hard git pull

     

    Processed: 0.010, SQL: 9