Git을 배우기: Merge Conflict 무엇인지?

Source: Axosoft Blog | Author: Jonathan Silva

Git으로 작업을 할때, 사용자는  커밋을 분리된 여러 두까지 브랜치에서 결합을 합니다. 변경 사항이 없으며 파일은 자동으로 병합됩니다. (즉, 커밋이 동일한 코드 라인을 다르게 업데이트)

Merge conflicts can traditionally cause developers a lot of grief, especially when working in the terminal, but GitKraken’s merge conflict tool helps users identify where the conflict is occurring and how to resolve it.

Watch this quick video or keep reading to learn more!

Download our Git GUI client for free, to easily resolve merge conflicts.

Download GitKraken Free

What is a Git Merge Conflict?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits.

I love merge conflicts meme

When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.

However, when there are conflicting changes on the same lines, a “merge conflict” occurs because Git doesn’t know which code to keep and which to discard.

When Can Merge Conflicts Occur?

Merge conflicts can happen when merging a branch, rebasing a branch, or cherry picking a commit.

where can merge conflicts occur

If Git detects a conflict, it will highlight the conflicted area and ask which code you wish to keep.

Once you tell Git which code you want, you can save the file and proceed with the merge, rebase, or cherry pick.

Resolve Merge Conflicts with GitKraken

While merge conflicts can be intimidating, they’re a snap with GitKraken.

Let’s say we have two branches that have modified the same line in the same file. When you drag-and-drop to perform a merge, GitKraken will detect the merge conflict and notify you that it needs your help.

GitKraken merge conflict editor

Click View Conflicts to view a list of conflicted files. Then, when you click a file, it will open the merge tool, showing you the conflicting changes between the two branches along with an output view at the bottom. You may check the box for each hunk of code you wish to keep or select the code one line at a time.

You can even type in the output box to fine-tune your code further. Once you’re satisfied with the changes, hit Save to exit the merge tool and proceed to the next conflicted file. After resolving all conflicted files, you may proceed with the merge.

Pro Tip: having the ability to edit code directly in the output box is a feature exclusive to GitKraken Pro.

Upgrade to GitKraken Pro.

Merge Conflicts with Deleted Files

As a second example, let’s say you attempt a merge where a file is deleted on one branch but not the other.

This will also trigger a merge conflict, but when you click to view the conflict, GitKraken will instead ask you to choose between three options:

  • Keep Modified Version will tell GitKraken to add back the deleted file along with any changes you made to that file.
  • Delete the File will tell GitKraken to delete the file and discard any of its changes.
  • And Keep Base Version will tell the app to add back the deleted file without any added changes from a branch.
merge conflicts with deleted file

After making your selection, you may commit and merge to proceed.

Easy Merge Conflict Resolution!

See, merge conflicts aren’t too bad, right!? Now you have the tools and expertise needed to resolve merge conflicts with the help of the GitKraken Git Client.

If you like this video, we encourage you to subscribe to our YouTube channel, watch our other Learning Git with GitKraken videos, and check back for more Git tips and training.

댓글 남기기