Unverified Commit 9992a5bb authored by Laurent Modolo's avatar Laurent Modolo
Browse files

fix first part of the TP

parent cf9febaa
......@@ -146,7 +146,7 @@ git status
git st
```
We defined `st` as an alias of `status` in the `~/.gitconfig` file, so the two command are equivalent.
We defined `st` as an alias of `status` in the `~/.gitconfig` file, so the two commands are equivalent.
Our first code:
......@@ -182,30 +182,27 @@ The current state of `data/letter.txt` is recorded.
![git add made a copy of the a file creating the corresponding blob](img/staging_1.png){height=150px}
```sh
echo 'b' > data/letter.txt
ls -R .git/objects/
git st
git ls-files --stage
echo "1234" > data/number.txt
git add data/number.txt
git ls-files --stage
printf "1" > data/number.txt
```
We changed the state of `data/letter.txt`, but those changes are not staged for commit.
The previous states of `data/letter.txt` is still recorded *somewhere* even if it differs from its current state.
We changed the state of `data/number.txt`, but those changes are not staged for commit.
The previous states of `data/number.txt` is still recorded *somewhere* even if it differs from its current state.
This *somewhere* is called the staging area (where you stage changes).
![modifications in the working area don't affect what's stored in Git](img/staging_2.png){height=150px}
```sh
git ls-files --stage
printf '1234' > data/number.txt
git add data/number.txt
git ls-files --stage
printf '1' > data/number.txt
git add data/number.txt
git ls-files --stage
```
![The staging area is different from the working directory](img/staging_3.png){height=150px}
![modifications in the working area don't affect what's stored in Git](img/staging_2.png){height=150px}
![The staging area is different from the working directory](img/staging_3.png)
You can save the state of the staging area definitively with the command `git commit`
......@@ -216,7 +213,7 @@ git st
Here "a1" is the message associated with the commit.
![Write clear and informative commit messages ([xkcd](https://xkcd.com/))](img/git_commit_xkcd.png){height=250px}
![Write clear and informative commit messages ([xkcd](https://xkcd.com/))](img/git_commit_xkcd.png)
> There are two rules for committing:
>
......@@ -232,7 +229,7 @@ git lo
```
You wrote your first commit with an unique identifier:
`8afd9d3fef28f7a9d582c9fa11d3702a9161feb4`
`531019e7119268c4dae5ac44ef5929165794f4b0`
> `git commit`:
> - creates a tree graph to represent the content of the version of the project being committed
......@@ -240,13 +237,13 @@ You wrote your first commit with an unique identifier:
> - points the current branch to the new commit object
```sh
git ls-tree -r 8afd9d3fef28f7a9d582c9fa11d3702a9161feb4
git ls-tree -d 8afd9d3fef28f7a9d582c9fa11d3702a9161feb4
git ls-tree -r 531019e7119268c4dae5ac44ef5929165794f4b0
git ls-tree -d 531019e7119268c4dae5ac44ef5929165794f4b0
```
The `8afd9d3fef28f7a9d582c9fa11d3702a9161feb4` point to the tree object with point to the two committed files.
The `531019e7119268c4dae5ac44ef5929165794f4b0` point to the tree object with point to the two committed files.
[The commit a1 record the tree structure and the files corresponding to the staging area](img/commit_a1.png){height=150px}
[The commit a1 record the tree structure and the files corresponding to the staging area](img/commit_a1.png)
In git, there are 3 areas:
......@@ -254,7 +251,7 @@ In git, there are 3 areas:
- The staging area (in the `.git` folder)
- The repository (also in the `.git` folder)
![git areas](img/three_git_areas.png){height=250px}
![git areas](img/three_git_areas.png)
The repository is a chain of commit beginning with your first commit.
......@@ -277,7 +274,7 @@ You can navigate to a given point of the repository with the command `git checko
```sh
git log
cat data/number.txt
git checkout 8afd9d3
git checkout 531019e
cat data/number.txt
```
......@@ -336,7 +333,7 @@ git lo
We are back at the leaf of the git repository.
### Growing the repository tree
## Growing the repository tree
We only have one branch, the `master` branch in our repository.
This mean that we only have one timeline in our history.
......@@ -350,9 +347,9 @@ git lo
```
```sh
echo '1' > data/number.txt
echo '3' > data/number.txt
git add data/number.txt
git commit -m "1: first commit in dev"
git commit -m "a3"
git lo
```
......@@ -360,17 +357,18 @@ If we have two branches `dev` and `master`, it's hard to tell them apart (`maste
```sh
git co master
echo 'c' > data/letter.txt
echo 'b' > data/letter.txt
git add data/letter.txt
git commit -m "c: third commit in master"
git commit -m "b2"
git lo
```
Congratulation you have a fork in your git repository !
Lets make another one called `dict` from the branch `master` where `data/letter.txt` contain the letter `d`.
Lets make another one called `dev2` from the branch `master` where `data/letter.txt` contain the letter `c`.
Then create the corresponding commit `c2`
### Merging branches
## Merging branches
When you are ready to incorporate your new code in your main branch you need to merge the branch containing the new code into your main branch.
You can merge branch with the command `git merge`.
......@@ -383,12 +381,12 @@ git branch
git merge master
```
Can we merge `master` into `dict` ?
Can we merge `master` into `dev2` ?
```sh
git co master
git branch
git merge dict
git merge dev2
```
There are three types of merge :
......@@ -419,13 +417,15 @@ 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 `data/numberber.txt` file while in the `master` branch, we worked on the `data/letter.txt` file.
Here, we didn't have any conflict: in the `dev` branch, we worked on the `data/number.txt` file while in the `master` branch, we worked on the `data/letter.txt` file.
Let's complicate things !
Create a new commit in the `master` branch where the content of `data/letter.txt` is set to `e`.
Create a new commit `e3` in the `master` branch where the content of `data/letter.txt` is set to `e`.
Then create a new commit in the `dev` branch where the content of `data/letter.txt` is set to `f` and go back the the branch `master`.
```sh
git lt
git branch
git merge dev
git st
......@@ -449,11 +449,12 @@ git add data/letter.txt
git st
git commit
git st
git lt
```
You now, know how to deal with the different kind of merge
## Part 2: Git togetherdata
# Part 2: Git together
We start by cloning an existing repository.
`file_handle.py` is a small python script to handle the dating and the access to dated files in a format compatible with the [guide of good practices at the LBMC](http://www.ens-lyon.fr/LBMC/intranet/fichiers/bioinfo/good-practices.pdf).
......@@ -644,9 +645,6 @@ git push perso
You can see the graph of our modifications at the following address [http://gitlab.biologie.ens-lyon.fr/user_name/git_basis/network/master](http://gitlab.biologie.ens-lyon.fr/user_name/git_basis/network/master)
# Part 2: Git Together
Branch management is at the heart of Git. These powerful mechanisms will help
you to work in collaboration with others. For the second part of the TP you
need to pair with someone else. We will refer to you as developer **W**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment