Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (19.7k points)

I'm trying to merge a pull request that has one conflict in one file (see below). The instructions for merging the pull request are provided by Github are as follows. It's important to perform this merge so the person submitting the pr gets credit for it.

# Step 1: From your project repository, check out a new branch and test the changes.

git checkout -b droark-master master

git pull https://github.com/droark/cryptopp.git master

# Step 2: Merge the changes and update on GitHub.

git checkout master

git merge --no-ff droark-master

git push origin master

I know how to fix the one line in the one conflicting file. What I don't know how to do is make Git perform the merge and stop complaining about broken index files.

How do I make Git perform the merge, ensure the person who provided the pull request gets credit for it, and stop breaking index files?


I tried to repair the merge with Git merge errors. One set of errors turns into another set of errors, ad infinitum. I also tried resetting the problem file according to Ignore files during merge with plans to copy/paste the one line needed, but the broken index persists.

This has turned into a complete waste of time, and I am no longer interested in trying to do it Git's way since it wastes so much time. Now I simply want Git to perform the merge and stop breaking index files.


Here is the output produced when merging using Github's instructions:

$ git pull https://github.com/droark/cryptopp.git master

From https://github.com/droark/cryptopp

 * branch            master     -> FETCH_HEAD

Auto-merging validate.h

Auto-merging validat2.cpp

Auto-merging validat1.cpp

Auto-merging test.cpp

CONFLICT (content): Merge conflict in test.cpp

Auto-merging pubkey.h

Automatic merge failed; fix conflicts and then commit the result.

1 Answer

0 votes
by (62.9k points)

There's no way to merge without resolving conflicts. Otherwise, how would git know what to merge? You can, however, check out the version from either branch you're merging using git checkout --ours <filepath> or git checkout --theirs <filepath>. Here's an example:

Suppose you're on the master branch merging in staging:

git checkout master

git merge staging

And git shows a bunch of conflicts:

...

CONFLICT: Readme.md

...

If you want to keep the version of Readme.md which is on the master branch, then you would need to run the following command:

git checkout -- ours Readme.md

Note that since you're on master --ours refers to the master branch.

Now, you can simply add it to the index to mark it as resolved:

git add Readme.md

This will effectively ignore any changes made to Readme.md file on the staging branch.

You can repeat this process for each file you want to remove from the merge. When you're done, commit as you normally would:

git commit -m "some_msg"

In order to repeat it for all files with conflicts you can try the following:

for f in $(git diff --name-only --diff-filter=U | cat); do

   echo "Resolve conflict in $f ..."

   git checkout --theirs $f

done

Related questions

+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...