I studied what is the git merge
operation and what it does when it discovers a conflict that is not able to solve automatically.
If I can solve manually the conflicts I can choose what I want to save and what I want to change.
On the other hand we have the fast forward merge, if one branch is direct ancestor of the other, and on the other hand the not fast forward merge but automatically solved.
Here I find difficul to understand how Git treats these two cases: I've seen it selects automatically what to change but I how can I know if it's doing the things as I want?
For example on the test
branch I worked with file.txt while on master
branch I have another version of file.txt.
The two branches share a common ancestor.
I execute git checkout master
and then I want to merge with test
.
To do so I digit git merge test
. Then what could happen?
master
has a completely different contentmaster
has text that wasn't present inside thetest
version of file.txtmaster
has fewer pieces of text than the file.txt insidetest
My question concerns a generic case: How can I understand, beforehand run git merge test
, how Git will treats these merges?
Maybe it depends on which branch I'm currently in when I start git merge
?
CodePudding user response:
How can I understand, beforehand run git merge test, how Git will treats these merges?
You can't understand it beforehand but you can do the merge without actually making the merge commit and thus you can study the outcome. Just say
git --no-ff --no-commit merge test
and then look around.
CodePudding user response:
How can I understand, beforehand run
git merge test
, how Git will treats these merges?
In some rare (and basically never produced unintentionally) cases there will be additional preparatory work layered underneath the fundamental operation, or the entire thing can in the trivial "fast-forward" cases just be sidestepped, but: to see what git merge test
will be working with, say
git diff ...test # diffs on test since histories diverged
git diff test... # diffs in checkout since test history diverged
and those are the two sets of diffs Git will be merging.
Git has a default automerge that applies all hunks that don't overlap or abut any different changes on the other tip, but overlapping or abutting change hunks can't be reliably automerged, no one's ever figured out how to derive a "right" general result for those so you have to sort that out.