5: Multiple Conflicts( Merge Conflicts )

When working with a larger team, it's possible to have multiple merge conflicts; both multiple conflicts in a single file, and conflicts in multiple files. When working on large projects, with many files, it's common for a single branch to alter dozens of files. When this happens, you may face merge conflicts that are tricky to resolve.

Although we won't be using them here, this is where git's graphical merge tools can be useful. To use them, you'll need to run the git mergetoolcommand. You'll also generally want to specify the --tool option flag to specify which graphical tool to use. You can see a full list of available tools on your system by running git mergetool --tool-help.

A graphical merge tool will show you the branches side by side, and highlight differences visually, like this:

bDtKd0S.png

In this particular tool, the HEAD branch is on the right, and called the REMOTE branch, the branch we're merging is on the left and called the LOCALbranch, and the final version is in the center. We need to edit the center version to get the result we want, then save it.

In the absence of a graphical tool, it's still possible to sort through multiple merge conflicts, it's just a bit more work. All of the merge conflict markup must be removed before committing if there are multiple conflicts.

Instructions

  • Switch into the /home/dq/chatbot repo.
  • Switch to the master branch.
  • Create a branch that inserts print statements into bot.py.
    • Create a branch called feature/more-printing in the repo chatbot.
    • Switch to the branch feature/more-printing.
    • Edit bot.py and add multiple lines that print whatever text you want.
    • Commit your changes.
  • Create another branch that inserts print statements intobot.py.
    • Switch to the master branch.
    • Create a branch called feature/more-printing-2 in the repo chatbot.
    • Switch to the branch feature/more-printing-2.
    • Edit bot.py and add different print statements to the same lines you edited in feature/more-printing.
    • Commit your changes.
  • Create a merge conflict.
    • Merge feature/more-printing into master.
    • Try merging feature/more-printing2 into master.
    • At this point, you should trigger multiple conflicts.
  • Resolve the merge conflict.
    • Resolve the conflicts by editing bot.py and keeping whatever lines you want.
    • Commit bot.py with the message Resolved multiple conflicts.
  • Push the master branch of chatbot to the remote repo

 

~$ cd ~

~$ cd chatbot

~$ git checkout -b feature/more-printing

~$ printf "\nmessages=['I am great', 'You are great', 'I need more outside time']\nimport random\nmsg=random.choice(messages)\nprint(msg)" >> bot.py

~$ git add .

~$ git commit -m "Add more printing"

~$ git checkout master

~$ git checkout -b feature/more-printing-2

~$ printf "\nimport random\nd1=random.randint(1,6)\nd2=random.randint(1,6)\nprint('D1: {0} D2: {1}'.format(d1, d2))" >> bot.py ~$ git add .

~$ git commit -m "Add even more printing"

~$ git checkout master

~$ git merge feature/more-printing

~$ git merge feature/more-printing-2

~$ printf "\nimport random\nd1=random.randint(1,6)\nd2=random.randint(1,6)\nprint('D1: {0} D2: {1}'.format(d1, d2))" > bot.py

~$ git add .

~$ git commit -m "Resolved multiple conflicts"

~$ git push origin master

转载于:https://my.oschina.net/RobertPattins/blog/747120

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值