Resolving a conflict
- Git course
- Intermediate
- Lesson 14/82
- 4 min
Learn the steps to resolve a conflict by hand.
How Do You Resolve a Conflict?
When a merge conflict occurs, first open the affected file and inspect its conflict markers. You can manually edit the file to decide which changes should be kept.
<<<<<<< HEAD
console.log("Merhaba");
=======
console.log("Hello");
>>>>>>> featureRemove the markers and unnecessary sections, then save the file.
Staging the Resolved File
After editing the file and removing the conflict markers, you must tell Git that the conflict has been resolved. You do this by adding the file to the staging area with git add.
git add app.js
git statusYou can check the file's status with git status. Staging indicates that the resolved content is prepared for the next commit.
Practice Stage a Resolved File
Store the git add app.js command that should be executed after resolving a conflict in a JavaScript variable. Print the command with console.log().
Starter code
const stageCommand = "";
// Komutu yazdırSample solution
const stageCommand = "git add app.js";
console.log(stageCommand);Expected output
git add app.js
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What should you do first when resolving a conflict manually?
- Change the user configuration
- Recreate the repository
- Open the conflicted file and inspect its markers Correct answer
- Delete all files
Explanation: First, inspect the conflicted file. This helps you understand which contents are conflicting.
2 Stage the Resolved File
git add ____
git add app.js
Explanation: After editing the file, use git add app.js to add it to the staging area.
3 Conflict Resolution Steps
| Term | Meaning |
|---|---|
Dosyayı aç |
Inspect the conflicting content |
İçeriği düzenle |
Choose the changes to keep |
İşaretleri kaldır |
Remove the conflict markers |
git add |
Stage the resolved file |