1. 程式人生 > >[Git] error: Your local changes to the following files would be overwritten by merge

[Git] error: Your local changes to the following files would be overwritten by merge

如果系統中有一些配置檔案在伺服器上做了配置修改,然後後續開發又新新增一些配置項的時候,

在釋出這個配置檔案的時候,會發生程式碼衝突:

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

如果希望保留生產伺服器上所做的改動,僅僅併入新配置項, 處理方法如下:

git stash  //先隱藏本地的改變
git pull
git stash pop   //恢復的同時把stash內容也刪

然後可以使用Git diff -w +檔名 來確認程式碼自動合併的情況.

反過來,如果希望用程式碼庫中的檔案完全覆蓋本地工作版本. 方法如下:

git reset --hard
git pull
其中git reset是針對版本,如果想針對檔案回退本地修改,使用
git checkout HEAD file/to/restore