I have a scenario where one developer created a branch, made changes to a file and submitted changes to git. At the same time another developer created a different branch made changes to the same file at another location within the file and submitted changes to git. Both branches were merged. Why did the first developers changes disappear? Shouldn't git apply all the changes?
CodePudding user response:
When there is such conflict, there is usually a problem which is raised during the merging, saying something like: "a conflict needs to be resolved. Solve it and commit the changes". Then the different sections in conflicts are separated with >>>>>>>>>> and <<<<<<<<< with the ids of the commits, inside the concerned files.
Then the developer needs to resolve the conflict and commit the merge.
The dev has the possibility of saying resolve using our version or resolve using their version. It's pretty rough, because then the others changes are ignored completely.
And in this regard, I would say that it is not a problem of git or gitlab, but of the developer who merged the commits the lazy way (resolve using our version) without knowing what he was doing and the implications...
If you need to restore the ignored changes you will have to come back in the commit before the merge, and solve it by hand (you can try to merge the branch again as well).
I advise you using a visual editor while resolving conflicts (e.g. 'meld' or 'sublime merge').
CodePudding user response:
I think maybe or not, but it's a git issue, other than gitlab. So if you merge first developer's code , and then second... the first' code is disapear, caused by: they modified same code block and had a conflict, you ignore the first's code, use the second.
CodePudding user response:
Sounds like a bad merge, when merging in a branch that has the same file changed the file should conflict which you can then review in VSCode or any other IDE. You want to then "Accept Both Changes" above any changed section.
