SourceTree常見衝突解決

最近才用sourcetree進行移動開發的版本控制,涉及到了多人開發,遇到了寫衝突的解決,發現了這篇文章,寫的不錯!!!

 

 

Git現在越來越火,很多人都從Svn遷移到Git上面,Git讓我們更加與世界接軌,不再是“局域網”的程序猿,特別是掌握了Git之後,會發現它真的很好用,本文對Git中比較煩人的衝突進行了詳細的說明,希望能幫助那些剛接觸Git的程序猿。


亮點:

  • 採用可視化SourceTree插件beyondCompare更加接近svn衝突比較

構造衝突

  • A 修改了conflict.file 中第1行內容並且提交到git上
  • B 這個時候也修改了confilct.file中第一行內容準備提交,這個時候git就會提示
To git@192.168.x.xxx:xxx/server-aggregator.git
 ! [rejected]        develop -> develop (fetch first)
error: failed to push some refs to '[email protected]:xxx/server-aggregator.git'

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

提示遠程已經有更新了,本地版本太低,讓我們先pull拉取最新的代碼,

  • 我們繼續拉取代碼pull一下,這個時候由於本地有修改這個文件,就會在本地產生衝突文件

配置外部比較工具

解決衝突

  • 在本地副本->右鍵->解決衝突->打開外部合併工具

  • 和svn一樣解決好衝突保存更改,退出即可

另外一種情況

  • 拉取時出現如下提示:
it -c diff.mnemonicprefix=false -c core.quotepath=false pull local-server-aggregator develop
/opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell:3: warning: Insecure world writable dir /usr in PATH, mode 040777
From 192.168.0.200:weitoo/server-aggregator
 * branch            develop    -> FETCH_HEAD
Updating b0c5c94..40cef3b
error: Your local changes to the following files would be overwritten by merge:
    server/conflict.file
Please, commit your changes or stash them before you can merge.
Aborting

提示需要暫存本地修改,才能拉取服務器上新的代碼

  • 點擊貯存(英文版:Stash),隨便起一個名字,裏面存的都是距離上次服務器版本到本地修改之間的差異,千萬別刪掉了,合併成功無誤了再刪掉。

  • pull拉取服務器代碼,這個時候,本地的代碼變成了服務器上的代碼

  • 點擊貯藏->應用貯藏區 ,這個時候是把之前的修改合併到本地上,這個時候會提示衝突
git -c diff.mnemonicprefix=false -c core.quotepath=false stash apply stash@{0}
Auto-merging server/conflict.file
CONFLICT (content): Merge conflict in server/conflict.file

可以在sourcetree裏看到有感嘆號,代表衝突文件,和上面解決衝突方法類似,但是稍微不同,最左邊成了遠程版本,中間爲遠程上一個版本,最後纔是本地修改。
這個是和我們操作方式有關:我們是先暫存本地修改,先拉取遠程代碼,這個時候local 就成了遠程代碼,最後我們用暫存的合並進去,remote就成了本地修改

生成了多餘的.orig文件

這個是由於git自身造成的 它會解決衝突後 生成一個原來衝突的備份,我們可以去掉

git config --global mergetool.keepBackup false


感謝您的耐心閱讀,如果您發現文章中有一些沒表述清楚的,或者是不對的地方,可以給我留言
,當然你有其他類的需求文章,也可以私信我。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章