Git衝突:commit your changes or stash them before you can merge. 解決辦法

Git衝突:commit your changes or stash them before you can merge. 解決辦法

2018年04月09日 18:18:29 明天是spring 閱讀數 2568php

用git pull來更新代碼的時候,遇到了下面的問題:git

1spring

2工具

3spa

4.net

error: Your local changes to the following files would be overwritten by merge:
           *********************************************************
Please, commit your changes or stash them before you can merge.

Abortingcode

出現這個問題的緣由是其餘人修改了xxx.php並提交到版本庫中去了,而你本地也修改了xxx.php,這時候你進行git pull操做就好出現衝突了,解決方法,在上面的提示中也說的很明確了。ci

一、保留本地的修改 的改法

1)直接commit本地的修改 ----也通常不用這種方法get

2)經過git stash  ---- 一般用這種方法it

1

2

3

git stash

git pull

git stash pop

經過git stash將工做區恢復到上次提交的內容,同時備份本地所作的修改,以後就能夠正常git pull了,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的哪些節點都消失了。

二、放棄本地修改 的改法  ----這種方法會丟棄本地修改的代碼,並且不可找回

1

2

git reset --hard

git pull<br><br><br><br><br><br>

相關文章
相關標籤/搜索