-2

Please explain. Why there is no conflict here: screen without conflict

and here it is: screen with conflict

Is there any way to avoid such conflicts? Thanks a lot for the answers.

xaro93
  • 1
  • 2
    You can't really. This is the nature of decentralised source control. Conflicts come about when two people change the same line of the same file. – evolutionxbox Jan 05 '21 at 10:12
  • 1
    My question is more on why are you even tracking the composer.lock file? That file will change almost everytime you ran composer update on your project and you don't really gain anything on tracking that file since all the developers in your team will ran that command often. I normally only leave the composer.json in my repository and both the vendor folder and composer.lock are in my gitignore list. – marcogmonteiro Jan 05 '21 at 10:41

1 Answers1

1

Your question is strange because your are showing different things. But it shows that you didn't get something... because the answer is in the 2nd image: "file has been changed in source and destination".

The first image is the result of a change. (Side node: in the future, please include directly your image in your question)

The second image is a conflict occurring when you try to merge (or rebase) a commit.

and here it is: screen with conflict

In fact, this piece of code has been changed in the 2 branches you want to merge (or do something equivalent). So when git try to apply the patch on the file corresponding to the commit, it found that the line removed is not the one expected (sometimes it's even the context lines --the one above or below the change-- that just changed).

So the patch can't apply automatically (understanding patch file format here could help) and git ask you to solve the conflict i.e. decide which incompatibles changes you want to keep (or need your brain to merge the 2 changes).

Is there any way to avoid such conflicts?

There is no perfect way to avoid conflicts because that just means that 2 people worked on the same part of the file and so that a human have to make a choice.

One thing that you could sometimes do is to have the last version of the changes and do your changes after the other changes. That's more a team organization...

But when you work in branches that's not always possible.

Philippe
  • 28,207
  • 6
  • 54
  • 78