资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Git冲突中gitcheckout高级用法是什么

Git冲突中git checkout高级用法是什么,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

十余年的桥东网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网整合营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整桥东建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“桥东网站设计”,“桥东网站推广”以来,每个客户项目都认真落实执行。

 

背景

Git冲突的原因,一般是修改了同一个文件导致的,这个文件有可能是别人提交到远程仓库里面,还有就是需要合并这个文件导致的。

 

解决方法

  1. 你确定你需要的是哪个仓库的文件

git checkout --theirs conflicted_file.txt  # 保留远端的
git checkout --ours conflicted_file.txt # 保留本地的
 
  1. 然后执行add和commit

git add -A
git commit -m "update conflict
   

举个栗子

获取远端服务器上的文件,提示冲突了需要合并

# git cherry-pick FETCH_HEAD
* branch            refs/changes/85/12385/3 -> FETCH_HEAD
error: 'cherry-pick' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm ' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: cherry-pick failed
 

查看当前仓库的状态

# git status
Not currently on any branch.
You are currently cherry-picking commit 53e5374.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add ..." to mark resolution)
     both modified: file1.txt
 

用提示的命令执行

# git cherry-pick --continue

U   file1.txt

error: 'commit' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm ' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
 

提示file1.txt有更新,确定替换为远程仓库的文件。这里用theirs

git checkout --theirs file1.txt
 

然后添加到本地仓库

git add -A
 

最后继续cherry-pick「复制」

# git cherry-pick --continue
[detached HEAD 8f26ce8] Summary : test git checkout --theirs
 Author: Rik
 2 files changed, 0 insertions(+), 0 deletions(-)
   

小结

git ckeckout 和 带参数的--ours和 --theirs还是有区别的。

    

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


网页名称:Git冲突中gitcheckout高级用法是什么
文章起源:http://cdkjz.cn/article/gsdggo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220