Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How will Git merge this?

Tags:

git

John and Tom clone the same remote repo. The content of remote repo is like this:

FileA.c

John make a local commit like this, ie, it moves the FileA.c into a folder named John and commit it locally.

John\FileA.c

Tom also make a local commit like this, ie, it moves the FileA.c into a folder named Tom and commit it locally.

Tom\FileA.c

If Tom and John both push their local repos to the remote repo, say GitHub, how will Git merge this?

I hope I made myself clear. Thanks!

like image 597
smwikipedia Avatar asked Jan 19 '23 21:01

smwikipedia


2 Answers

When you do git commit but don't do git push, the changes are added in your local repository and are not committed to the global repo. So, whosoever pushes his changes first, he won't get any conflicts since the remote server doesn't know about the changes made by other user that are not yet pushed. Later when the next user tries to push the changes, git will give error that the global repo has been changed and you must pull the changes first. Since, the changes are in the same file and the location has been changed, There will be a conflict, which would not be resolved by git itself. The next user will have to make the changes again and push it so as to update the global repo.

like image 156
Vikram.exe Avatar answered Jan 29 '23 06:01

Vikram.exe


Git/SVN/etc, do a merge as best as possible: if they see that separate, non interfering lines of code have been added/deleted/modified, then it will simply combine those changes made by John/FileA.c and Karen/FileA.c (its become practice to make someone in your example a girl =P). If the merge script see's that the same lines of code have been edited then it will mark it as conflict in the file.

I think this point has been made, but this process occurs locally; either by Karen or John, depending on who was the person to try and push last. The person who pushed last will be notified to pull from the remote repo and resolve any conflicts before pushing their own changes.

like image 27
Nadir Muzaffar Avatar answered Jan 29 '23 07:01

Nadir Muzaffar