Skip to content
Snippets Groups Projects
Unverified Commit 193d113b authored by Laurent Modolo's avatar Laurent Modolo
Browse files

tp.md: add section on merging branches

parent 62ea29d5
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ ci = commit
st = status
lo = log --graph --decorate --date-order --all"
lg = "log --pretty=format:\"%h - %an : %s\""
lt = "git log --graph --oneline --all"
lt = log --graph --oneline --all
unstage = "reset HEAD"
```
......@@ -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.
## Cloning a git repository
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment