1. 程式人生 > >Git沖突:commit your changes or stash them before you can merge. 解決辦法(轉載)

Git沖突:commit your changes or stash them before you can merge. 解決辦法(轉載)

顯示 file abort 轉載 win htm 內容 class 也說

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

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

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

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

1)直接commit本地的修改

2)通過git stash

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的哪些節點都消失了。

2、放棄本地修改 的改法

git reset --hard
git pull

轉載請註明:知識螞蟻 ? Git沖突:commit your changes or stash them before you can merge. 解決辦法

Git沖突:commit your changes or stash them before you can merge. 解決辦法(轉載)