Thursday, 27 December 2018

GIT: Picking theirs or ours for conflicting file

If a file is in conflict, you can instruct Git to take the version from the new commit of the version of commit onto which the new changes are applied. This is sometimes easier than to solve all conflicts manually. For this you can use the git checkout with the --theirs or --ours flag. During the conflict --ours points to the file in the commit onto which the new commit is placed, i.g., using this skips the new changes for this file.
Therefore to ignore the changes in a commit for a file use the following command.
git checkout --ours foo/bar.java
git add foo/bar.java
To take the version of the new commit use the following command.
git checkout --theirs foo/bar.java
git add foo/bar.java

0 comments:

Post a Comment