The disposition is as follows:
There are two branches. each of them contains the file that was edited (the same).
When merging branches, what happens to this file?
Answer 1, authority 100%
In short: a merge conflict will occur and will need to be resolved somehow.
- For binaries: only select version A or B (or others if octomerge).
It happens that Git treats binary files as text files and then merge irreversibly spoils them. This primarily applies to office format files.
- For text files: a couple of options:
Manually resolve conflicts
After the merge, chunks from both merged versions will appear in the file, something like this:
& lt; & lt; & lt; & lt; & lt; & lt; & lt; HEAD file content from the first branch ====== file content from the second branch & gt; & gt; & gt; & gt; & gt; & gt; & gt; otherbranch
You will need to manually edit the conflicting file (or files) while remembering to remove the tags left by Git (
& gt; & gt; & gt; & gt; & gt; & gt; & gt; otherbranch ). Then:
git add conflicting-file-name.txt git commit -m'merged A and B '
Select one of the file versions
You can explicitly specify which file to select. Only suitable if one of the versions is not needed.
git checkout --ours a.txt git checkout --theirs a.txt git add a.txt git commit -m "added theirs"
Made you a test repository to clone right away and see how it works.
git clone https://github.com/NickVolynkin/git-merge-test.git cd git-merge-test git merge otherbranch open a.txt
The marks are visible in the file, you can now do the above actions with it.
Read more in the book Pro Git in Russian . It is a must to read it before working with branch merging. There is no substitute for a fundamental understanding of the process.
You can practice branching and merging here: Learn Git Branching .
Answer 2, authority 17%
problems with merge can arise due to the use of an inconvenient editor. Try changing your console editor to IDE or specialized software for these needs
Nick Volynkin threw off the theory