如果系統中有一些配置文件在服務器上做了配置修改,然后后續開發又新添加一些配置項的時候, 在發布這個配置文件的時候,會發生代碼沖突:
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
在 checkout 或者 rebase 時, 如果提示:
Please move or remove them before you can switch branches. Aborting
執行:
$ git clean -d -fx
有時 push 代碼的時候, 出現提示:
$ git push To ../remote/ ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '../remote/'
問題 (Non-fast-forward) 的出現原因在於: git remote 倉庫中已經有一部分代碼, 所以它不允許你直接把你的代碼覆蓋上去. 於是你有 2 個選擇方式:
- 強推, 即利用強覆蓋方式用你本地的代碼替代 git 倉庫內的內容
$ git push -f
- 或者先把 git 的東西 fetch 到你本地然后 merge 后再 push
$ git fetch $ git merge
轉載自 我思故我在。