Home > Enterprise >  How to pull from my distant repository and force conflict?
How to pull from my distant repository and force conflict?

Time:01-07

I have a large file on GitHub and the last commit from me is a simple modification of one line. Other people are working on this file. I would like, when I pull everything on my laptop (having the original repository), to obtain a conflict to solve for each modification that other people have done on the file. However, the way I have understood Git, I will have a conflict only if they have modified the line already modified in the last commit.

How to force all modifications to generate a conflict ?

If this help to understand what I want: something like the revision tool on Word to check each modification. But using Git and GitHub.

Thank you.

CodePudding user response:

I suspect you haven't got the concept of a conflict and the concept of a PR quite right so let me phrase it like this? A conflict arises when Git is unable to determine how to merge two edits that overlap with each other. This is generally a bad situation to be in, as it means we require a human to intervene and solve the problem.

If you are wanting to review changes, then you should do this via a PR. If a review needs to take place, then the changes should be made on a separate git branch, so you can review the PR and approve that they merge these changes. You can restrict who can commit on to your branch if necessary.

To answer the question directly, to force a conflict just view their commits, edit the same lines that they have, and then pull their commit. However hopefully you'll agree that PR is what you're after! :)

More info: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests

CodePudding user response:

What you want is not a conflict but a comparison. Git has a solution for that: it's called diff.

First of all, don't pull. Instead, say

git fetch

Now you have the current state of that file, but it hasn't been read into your working tree yet. Now say

git merge --no-ff --no-commit

Git will perform the merge but won't actually make a merge commit. Now compare the state of your file after the merge with the state of your file before the merge, by saying

git diff HEAD -- myCoolFile

(or whatever the path to your file is). This will generate a diff where you can see all the changes that were made at the remote in contrast to what you have. You can use this as a guide to make edits to your file before actually adding and committing to finish the merge.

There are tools that will help you see the diff more clearly. For example there are graphical tools that present the two versions of a file side by side. But that is a well covered topic and isn't what you asked in any case.

  • Related