In Git, when you encounter a merge conflict, you have to decide how to resolve the conflict. Git provides several options to handle conflicts, including accepting the current version (your local changes), accepting the incoming version (the changes from the branch you are merging), or manually editing the conflicted files.
Here’s how you can accept the current version or the incoming version:
Accepting the Current Version
To accept the current version (your local changes) and mark the conflict as resolved, you can use the following command:
sh
git checkout --ours <file>
git add <file>
git checkout --ours <file>: This command checks out the current version of the file, overwriting the conflicted changes with your local version.
git add <file>: This stages the resolved file, marking the conflict as resolved.
Accepting the Incoming Version
To accept the incoming version (the changes from the branch you are merging) and mark the conflict as resolved, you can use the following command:
sh
git checkout --theirs <file>
git add <file>
git checkout --theirs <file>: This command checks out the incoming version of the file, overwriting the conflicted changes with the version from the branch you are merging.
git add <file>: This stages the resolved file, marking the conflict as resolved.
Example
Suppose you have a conflict in a file named example.txt. Here’s how you would accept the current version: