Git merge to solve the conflict in order to facilitate change during pull

This translation from: Resolve Git Merge a Conflicts in Favor of Their Changes During A pull

How do I resolve a git merge conflict in favor of pulled changes? How do I git merge to solve the conflict in order to facilitate change?

All the I need to the Remove Basically conflicting Changes from the without the HAVING A Working Tree to Go through at The All of a Conflicts with A git mergetool. All the while keeping as Free-Conflict Changes Basically, I need to remove all the conflicting change from working tree without having to use git mergetoolexperience all conflicts, while retaining all conflict-free changes. Preferably doing this while pulling, not afterwards . Best to do so when you pull in, rather than after.


#1st Floor

: Reference changes during https://stackoom.com/question/istj/ resolve merge conflicts in order to facilitate pulling Git


#2nd Floor

At The recursive This CAN use by You "theirs" at Strategy the Option : You can use recursion "their" policy options :

git merge --strategy-option theirs

At The the From man : from men :

ours
    This option forces conflicting hunks to be auto-resolved cleanly by 
    favoring our version. Changes from the other tree that do not 
    conflict with our side are reflected to the merge result.

    This should not be confused with the ours merge strategy, which does 
    not even look at what the other tree contains at all. It discards 
    everything the other tree did, declaring our history contains all that
    happened in it.

theirs
    This is opposite of ours.

Note: AS man at The Page (Pic), at The "Ours" Merge at Strategy the Option IS at The Very Different from "theirs" Merge at Strategy . Note: As the man page, "our" merger policy options with "their" merger strategies are very different .


#3rd floor

git pull -s recursive -X theirs <remoterepo or other repo>

Or, simply, for the default repository : or, simply, for the default repositories:

git pull -X theirs

If you're already in conflicted state ... If you are already in a state of conflict ...

git checkout --theirs path/to/file

#4th floor

OK so, picture the scenario I was just in: Well, just imagine what I encountered:

A attempt by You merge, or Maybe A cherry-pick, and you're stopped with your attempt merge, or cherry-pick, but you stopped

$ git cherry-pick 1023e24
error: could not apply 1023e24... [Commit Message]
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Now, you view the conflicted file and you really do not want to keep your changes. Now, you view the file conflict, and you do not want to keep the changes. In my case above, the file was conflicted. On just a newline my IDE had auto-added in the example above, the files in conflict newline my IDE automatically added. To undo your changes and accept their's , the easiest way is: To undo changes and accept the changes, the easiest way is:

git checkout --theirs path/to/the/conflicted_file.php
git add path/to/the/conflicted_file.php

The converse of this (to overwrite the incoming version with your version) is opposite (cover with your version passed version) is

git checkout --ours path/to/the/conflicted_file.php
git add path/to/the/conflicted_file.php

Surprisingly, I could not find this answer very easily on the Net. Surprisingly, I can not find the answer on the network.


#5th Floor

To resolve all conflicts with the version in a particular branch: To resolve all conflicts with a specific branch version:

git diff --name-only --diff-filter=U | xargs git checkout ${branchName}

So, if you are already in the merging state, and you want to keep the master version of the conflicting files: So, if you are already in the main version of the combined state and want to keep the conflict file:

git diff --name-only --diff-filter=U | xargs git checkout master

#6th floor

You're already in conflicted IF State, and you want the Just to the Accept All of theirs: If you are already in a state of conflict, and they want to accept all of the state:

git checkout --theirs .
git add .

If you want to do the opposite: If you want to perform the reverse operation:

git checkout --ours .
git add .

This is pretty drastic, so make sure you really want to wipe everything out like this before doing it. It's so intense, so make sure you really want to do this first before all the contents removed.

Original articles published 0 · won praise 73 · views 550 000 +

Guess you like

Origin blog.csdn.net/w36680130/article/details/105292910