1. 程式人生 > >Git:代碼沖突常見解決方法

Git:代碼沖突常見解決方法

服務 nbsp 發布 配置文件 merge reset com main clas

如果系統中有一些配置文件在服務器上做了配置修改,然後後續開發又新添加一些配置項的時候,

在發布這個配置文件的時候,會發生代碼沖突:

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

然後可以使用git diff -w +文件名 來確認代碼自動合並的情況.

反過來,如果希望用代碼庫中的文件完全覆蓋本地工作版本. 方法如下:

git reset --hard
git pull

其中git reset是針對版本,如果想針對文件回退本地修改,使用

 git checkout HEAD file/to/restore

Git:代碼沖突常見解決方法