日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

「GIT SourceTree冲突」解决方案

發(fā)布時(shí)間:2024/9/20 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 「GIT SourceTree冲突」解决方案 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

現(xiàn)在程序猿標(biāo)配GIT作為代碼管理,但是從SVN到GIT學(xué)習(xí)中,其中GIT的沖突是一個(gè)難點(diǎn),常常會(huì)導(dǎo)致Push不上去,Pull不下來,很尷尬的地步,還不知道自己寫的代碼被覆蓋沒,廢話不多說,直接上干貨!


亮點(diǎn)

采用SourceTree插件和BeyondCompare?可視化解決沖突

方法

構(gòu)造沖突

  • A 修改了conflict.file 中第1行內(nèi)容并且提交到git上

  • B 這個(gè)時(shí)候也修改了confilct.file中第一行內(nèi)容準(zhǔn)備提交,這個(gè)時(shí)候git就會(huì)提示

To git@192.168.x.xxx:xxx/server-aggregator.git! [rejected] develop -> develop (fetch first) error: failed to push some refs to 'git@192.168.xx.xx: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.

提示遠(yuǎn)程已經(jīng)有更新了,本地版本太低,讓我們先pull拉取最新的代碼。

  • 我們pull一下,這個(gè)時(shí)候由于本地有修改這個(gè)文件,就會(huì)在本地產(chǎn)生沖突文件

配置外部比較工具

  • 下載Beyond Compare

  • 打開SourceTree->工具->選項(xiàng)->比較->外部差異對(duì)比合并->選擇BeyondCompare

解決沖突

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

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

另外一種情況

  • 拉取時(shí)出現(xiàn)如下提示:

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

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

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

  • pull拉取服務(wù)器代碼,這個(gè)時(shí)候,本地的代碼變成了服務(wù)器上的代碼。

  • 點(diǎn)擊貯藏->應(yīng)用貯藏區(qū) ,這個(gè)時(shí)候是把之前的修改合并到本地上,這個(gè)時(shí)候會(huì)提示沖突。

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里看到有感嘆號(hào),代表沖突文件,和上面解決沖突方法類似,但是稍微不同,最左邊成了遠(yuǎn)程版本,中間為遠(yuǎn)程上一個(gè)版本,最后才是本地修改。
這個(gè)是和我們操作方式有關(guān):我們是先暫存本地修改,先拉取遠(yuǎn)程代碼,這個(gè)時(shí)候local 就成了遠(yuǎn)程代碼,最后我們用暫存的合并進(jìn)去,remote就成了本地修改

多余的.orig文件

這個(gè)是由于git自身造成的 它會(huì)解決沖突后 生成一個(gè)原來沖突的備份,我們可以去掉

git config --global mergetool.keepBackup false

總結(jié)

以上是生活随笔為你收集整理的「GIT SourceTree冲突」解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。