A
A
Alexander2017-05-25 16:43:01
git
Alexander, 2017-05-25 16:43:01

What happens when you merge branches (git merge)?

I work locally via GIT GUI or SourceTree . There was originally a master branch . I created a development branch and I'm working in it. Naturally, I already made several commits, deleted folders or enclosed them in .gitignore . Then I did a merge ( merge ) development into master . I send it to Bitbucket, from there I take it ( git clone ) to the VPS - then I see those folders that are not locally in the development branch . It turns out, firstly, git clone took the master branch , and secondly, mergedoes not mean that the branch becomes completely identical to the other? Explain, pliz, if there are branches incl. and different files, what happens to them when merge? And when switching from one vertex to another, if there are different files, then the files in Explorer will change visually, or what? ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2017-05-25
@sanok_ps

Imagine you have two trucks. At first they were equally empty, then you loaded a couple of sandbags into one truck and a bag of coal into another.
Conventionally, the first truck is master, the second is dev.

git checkout master
git merge dev

Now in master we have sandbags and a bag of coal
. And in dev, as before, only a bag of coal.
So you have not only those folders that are in development, but also those that were in master.
If you pushed the development branch, then when you clone it, it should also be pulled together, just at the moment git looks at master. Write git status to check which branch you are on and switch to the correct one.
If there is no development branch, you will need to push it first.
If two branches have different files (not contradictory), then merge simply places them all together, as if you copied files from one branch to another.
But if two branches have different content in files with the same name, auto-merging is performed, i.e. an attempt to automatically merge two contents into one. This operation is successful, for example, if you simply added one more line to the end of the file in one of the branches, and did not touch the file at all in the other branch.
If the content has changed in both branches, a conflict occurs. Git inserts something like
<<<<HEAD 
один контент
<<< commit1111
другой контент 
<<<end

You will have to decide what to do with such content: what to remove and what to leave.
After the conflict is resolved, you simply commit your solution, as if there were never two different versions of the files, but the version that you committed during the conflict resolution process was immediately there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question