如果一個文件在服務器上已經做了修改,然后在本地開發中又做了一些修改的時候,再發布這個文件時很容易造成代碼沖突,錯誤如下,
error: Your local changes to the following files would be overwritten by merge: lib/Models/App.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