[Git] 2 Ways to Fix git cherry-pick Conflicts
How to deal with “CONFLICT (content): Merge conflict in {file_name}”?
Have you encountered conflicts while cherry-picking a commit? No worries. It’s a common situation, especially when many engineers are working together. This article demonstrates how I fix conflicts with Visual Studio Code[1], Git Bash[2], and TortoiseGit[3]. Let’s start!
💡 Contents:
- Method 1: Solve with Visual Studio Code and Git Bash
- Method 2: Solve with TortoiseGit
Method 1 : Solve with Visual Studio Code and Git Bash
Visual Studio Code is my favorite editor while programming. It’s extremely powerful with numerous extensions. It also has an elegant interface to fix git conflicts.
Fix Conflicts
If git conflicts happen, there are four options to deal with this issue — Accept Current Change, Accept Incoming Change, Accept Both Changes, and Compare Changes.
The functionalities of these options are intuitive. Besides clicking on these options, you may also ignore the suggestions, and edit the code manually.
How to undo if I clicked on the wrong option?
Feel free to play with these options, and see the different outcomes. If you click on the wrong option accidentally, don’t worry. You could simply undo with Ctrl+z
.
Check in the Changes with Git Bash
Once I’m done with fixing conflicts, I’m used to open Git Bash, and check-in the changes with commands.
git status
git add my_file
git cherry-pick --continue
That’s it! You’re all set.
Method 2 : Solve with TortoiseGit
TortoiseGit is a Windows shell interface to Git. It has a friendly user interface and hence the engineers wouldn’t need to remember plenty of commands. If the status of a file shows “conflict” on working tree changes, double click on the file, then you could easily fix it by the pop up window.
Fix Conflicts
There are four options to deal with this issue — Use left text block, Use right text block, Use left text box then right, and Use left text box then left. You could fix the conflicts line by line with different options. You may also fix multiple lines at the same time by highlighting specific lines. Let’s see how these four options work.
Check in the Changes
TortoiseGit supports check-in the changes. Once you’re done with your changes, you may click “Mark as resolved”, and commit.
Other Useful Options on TortoiseGit
Navigate box is helpful while you’re fixing conflicts on a big file. The options are — Previous difference, Next difference, Previous conflict, Next conflict, Previous inline difference, and Next inline difference. These options help you quickly navigate to the target lines.
Summary
If you encounter conflicts while cherry-picking the files, don’t worry! Visual Studio Code and TortoiseGit are your best friends to assist you. Happy coding!
-2022.05.15。