Topic 4
Conflict
A conflict is not a disaster. It simply means Git needs help choosing between overlapping edits.
What a conflict means
A conflict appears when two sets of changes touch the same lines or the same small region of a file. For a push or pull to succeed cleanly, the file on GitHub and the local file you started editing from should match.
If they are different, pushing or pulling will result in a conflict (refer to the picture below). Git stops and asks you to decide what the final text should be. Let’s learn how to resolve this issue.
After that warning, click ‘Cancel’. Execute the command “pull”.
Then you will be able to see the following screen where the staging will be canceled. The green box displays the modifications made locally, while the blue box displays the content from GitHub.
Three options
There are three options, and you can click the one you prefer:
| Option | What happens |
|---|---|
Accept Current Change |
Only the modifications made locally will be accepted, and the content on GitHub will be discarded. |
Accept Incoming Change |
The modifications made locally will be discarded, and only the content on GitHub will be accepted. |
Accept Both Changes |
Both the local and GitHub contents will be accepted. This is the safest option. |
For example, if you click on ‘Accept Both Changes’, you will be able to see a screen similar to the one on the right. Now, execute the compilation (or saving).
Finish the merge
In the source control, click on the ‘+’ button in ‘Merge Changes’, and also click on the ‘+’ button in ‘Changes’. Then you will be able to see that all the changes have been staged, just like the screen on the right.
Proceed with the command “Commit & Push”. Thus, the conflict has been resolved.
If you can explain what the final file should say and the repository returns to a clean state afterward, the conflict has been handled correctly.