@@ -323,13 +323,82 @@ When you are ready to incorporate your new code in your main branch you need to
You can merge branch with the command `git merge`.
This command is going to try to merge the targeted branch into the branch you are on (*HEAD*).
The command `git branch` shows you the available branches and the one you are on.
```sh
git branch
git merge master
```
Can we merge `master` into `dict` ?
```sh
git co master
git branch
git merge dict
```
There are three types of merge :
- Fast-forward
- Merge of two different lineages
- Merge of two different lineages with conflict
Here the branch `dict` is a direct descendant of `master`.
`dict` contain all the information contained in `master`.
For `master` to gain all the information contained in `dict`, we just have to move the label `master` to the commit pointed by `dict`
```sh
git lo
```
There is a fork between the branch `master` and `dev`, we have to merge two different lineages.
```sh
git branch
git merge dev
```
Here the command create a *merge commit*, a merge commit is a commit that have two direct ancestors.
A new commit means a new commit message to write.
```sh
git lo
```
The new commit is a `Merge` commit with the identifiers of its two ancestors.
Here, we didn't have any conflict: in the `dev` branch, we worked on the `src/number.txt` file while in the `master` branch, we worked on the `src/dict.txt` file.
Let's complicate things !
Create a new commit in the `master` branch where the content of `src/dict.txt` is set to `e`.
Then create a new commit in the `dev` branch where the content of `src/dict.txt` is set to `f` and go back the the branch `master`.
```sh
git branch
git merge dev
git st
```
The automatic merge fail due to a conflict in `src/dict.txt`.
You are now in a merging state.
You must solve the conflict by editing `src/dict.txt`.
You can see three things in the `src/dict.txt`:
- The state of the file in your current branch (*HEAD*)
- The state of the file in the last common ancestor of the two branches
- The state of the file in the merged branch (*dev*)
Edit `src/dict.txt`, to set its content to `f`.
Then complete the merge:
```sh
git add src/dict.txt
git st
git commit
git st
```
You now, know how to deal with the different kind of merge.