Skip to content

Commit

Permalink
Merge pull request firstcontributions#934 from smoholkar/merge-conflicts
Browse files Browse the repository at this point in the history
how-to-resolve-merge-conflicts
  • Loading branch information
Roshanjossey authored Oct 16, 2017
2 parents e8987b3 + 951c5a7 commit dbaeed2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions additional-material/additional-material.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This document provides information about how to amend a commit on the remote rep
This document provides information about how to undo a commit on your local repository. This is what you need to do when you feel you've messed up your local repository and wish to reset the local repository.
> Take these steps if you want to undo/reset a local commit.
### [ Resolving Merge Conflicts ](resolving-merge-conflicts.md)
This document provides information about how to resolve merge conflicts.
> Take these steps to resolve the annoying merge conflicts.
### [Useful Links](Useful-links-for-further-learning.md)
This document is dedicated to all the blog posts, helpful sites, tips and tricks websites that makes our lives easier. That we refer to for all our needs, be it a beginner or an expert. This page should act as an index of all those useful links that would help everybody who is new in the open-source domain or someone who wants to learn more.

35 changes: 35 additions & 0 deletions additional-material/resolving-merge-conflicts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# What is a merge conflict ?

When you try to merge another branch into your current working branch, you are taking changes from another context and combine them with your current working files.
If two people changed the same lines in that same file, or if one person decided to delete it while the other person decided to modify it, Git simply cannot know what is correct. Git will then mark the file as having a conflict - which you'll have to solve before you can continue your work.

# How to resolve a merge conflict?

When faced with a merge conflict, git will mark the problematic area in the file by enclosing it in “<<<<<<<< HEAD” and “>>>>>>>>>>[other branch name]

The contents after the first marker originate from your current working branch. After the angle brackets, Git tells us where (from which branch) the changes came from. A line with "=======" separates the two conflicting changes.
Our job is now to clean up these lines: when we're done, the file should look exactly as we want it to look. It can be necessary to consult the teammate who wrote the conflicting changes to decide which code is finally correct. Maybe it's yours, maybe it's his - or maybe a mixture between the two.

eg:
```
<<<<<<< HEAD:mergetest
This is my third line
=======
This is a fourth line I am adding
>>>>>>> 4e2b407f501b68f8588aa645acafffa0224b9b78:mergetest
```

<<<<<<<: Indicates the start of the lines that had a merge conflict. The first set of lines are the lines from the file that you were trying to merge the changes into.
=======: Indicates the break point used for comparison. Breaks up changes that user has committed (above) to changes coming from merge (below) to visually see the differences.
>>>>>>>: Indicates the end of the lines that had a merge conflict.
You resolve a conflict by editing the file to manually merge the parts of the file that git had trouble merging. This may mean discarding either your changes or someone else's or doing a mix of the two. You will also need to delete the '<<<<<<<', '=======', and '>>>>>>>' in the file.


Once you have resolved the conflict do `git add`. Do not forget to run the tests that you have to make sure you have resolved the conflict correctly.

You can also download different plugins depending on the IDE you are using for an easier way to resolve merge conflicts.


# How to undo a merge ?
If you want to undo a merge then you can do `git merge —abort`

0 comments on commit dbaeed2

Please sign in to comment.