Prashant Singh
Prashant Singh

Reputation: 536

file got changed on master after I raised the merge request

Trying to figure out how the file1.cpp will look after merging merge request in Gitlab . I(dev1) am working on the dev branch and changed line 2 of file1.cpp, committed and raised merge request . Now, I waited 1 day before merging . By the time another developer(dev2) changed the line 4 of file1.cpp, committed and merged in master . Now, the line 4 is different in my file1.cpp, if compared to file1.cpp from master .So if I merge now my request then how the final version of file1.cpp will look like ?

1) file1.cpp:  
line 2 by dev1 
... 
line 4 by dev2

2) file1.cpp: 
line 2 by dev1
...
line 4 by dev1

My doubt is whether line 4 from my will change will be present in final file or line 4 from dev2 will be finally present . If line 4 from dev2 will be finally present , then why it is so ? Because my changes are coming after dev2's changes .

Upvotes: 1

Views: 768

Answers (1)

LeGEC
LeGEC

Reputation: 51840

git will not silently discard your colleague's changes, nor your own changes.

It will either :

  • find a way to combine both your changes,
  • or trigger a so called merge conflict, and ask someone to take manual action to determine what should be the end result.

If a merge conlict occurs, a generic manual action is :

  • fetch all changes on your machine,
  • rebase your work on top of the updated master branch,
  • fix the merge conflicts locally,
  • push your updated branch.

Note that "the changes are automatically merged by git" is not a guarantee that your code will work.

Two examples :

Suppose your change is : renaming function computeThis to computeThat,
and dev2's change is : call function computeThis,
your combined changes would lead to something that doesn't compile.

Suppose your change is : add a x -= 1 instruction,
and dev2's change is : add a double d = 1 / x,
and for some reason, before your change the code explicitly stated that x > 0 in that function,
the result would compile, but there could be a new bug case when x == 1.

Just to highlight :

the end result should still be tested and reviewed.

Upvotes: 2

Related Questions