git merge --merge
You can merge with the "git merge" command. The argument of git merge is the commit ID, but branch is the name of the commit ID, and for everyday use, specify the branch name. And merge. The merge destination is the current current branch.
git merge branch name
What is a merge?
Merging is the incorporation of changes made to the source code.
For example, suppose you have a file called "a.txt" in my current main branch.
Contents of "a.txt" in my current main branch
foo bar bar
Let's say Marshmallow worked and committed in a branch called "masu_fix_bug" that was derived from the "main" branch. And "a.txt" became as follows.
Contents of "a.txt" in Marshmallow's "masu_fix_bug" branch
foo bar bar baz
I want to include the contents of Marshmallow's "masu_fix_bug" in the "main" branch.
In such a case, the function called merging analyzes the difference and captures it. You can check the difference with the " git diff" command.
git diff The name of the branch you want to merge
Merge algorithm
There are multiple algorithms applied to merging.
Fast forward merge
The simplest merge algorithm. If a merge is possible by simply proceeding with the commit, this will be selected.
Non-fast forward merge
Merges the differences from the positions of the common ancestors of the two branches. Marges may conflict.
What surprises me here is that when merging, a command line editor such as vi is launched. am.
If there are no problems, switch to command mode with "ESC" and press "wq" "Enter" (save and exit) to complete the merge.
Resolving merge conflicts
If the merge conflicts, you need to resolve the conflict. In case of collision, the following will be displayed in the source code. I changed the path to "/ foo" and Marshmallow changed the text to "Good bye", so it clashed.
Before the code <<<<<<<< HEAD <a href="/foo"> Hello</a> ======= <a href="/bar"> Good bye</a> >>>>>>> masu_fix_bug Behind the code
You need to think about what this part should be and fix it manually. Here is an example of a fix.
Before the code <a href="/foo"> Good bye</a> Behind the code
Now you have a content that correctly reflects the changes made by the two.
After that, use the git add command to "git add." And git commit. All you have to do with the command is the normal commit procedure to commit.