Exercises - Basic Commands¶
Try out the basic commands¶
The purpose of this exercise is to learn about basic commands further.
- Create a folder called “mysecondrepo” which will contain your repository.
Tasks:
- initialize the repository
- create a README.md file and add this text on the first line: “File created on Sep. 30, 2020”
- stage the file
- commit the changes
- create a second file “Poem.md” without any text (hint: use touch command), stage and commit it
- Copy and paste the two paragraphs below of the poem la lluvia by Jorge Luis Borges into the Poem.md file:
Tasks:
- stage the first paragraph only
- confirm that the file has been partially staged by checking the status.
- check if the staged changes correspond to just the first paragraph by looking at the differences between: – the working directory vs. the staging area – the staging area vs. the committed changes region (Repo)
- commit the staged changes and check the status
- stage the second paragraph and commit the changes
Bruscamente la tarde se ha aclarado
Porque ya cae la lluvia minuciosa.
Cae o cayó. La lluvia es una cosa
Que sin duda sucede en el pasado.
Quien la oye caer ha recobrado
El tiempo en que la suerte venturosa
Le reveló una flor llamada rosa
Y el curioso color del colorado.
4. (Challenge task) Add the next paragraph of the poem:
Esta lluvia que ciega los cristales
Alegrará en perdidos arrabales
Las negras uvas de una parra en cierto
Patio que ya no existe. La mojada
Tarde me trae la voz, la voz deseada,
De mi padre que vuelve y que no ha muerto.
stage the changes and commit them. Now, we have the last four commits refering to the same topic (same poem). The goal of this part of the exercise is to summarize those four commits into a single one.
hint: git rebase -i HEAD~4
5. End of exercise
git diff usage¶
The purpose of this exercise is to show you the usage of the git diff command.
- Create a folder called “myfirstrepo” which will contain your repository.
Tasks:- initialize the repository
- create a README.md file and add this text on the first line: “File created on Sep. 30, 2020”
- stage the file
- commit the changes
At this point, your working directory, the staging area, and the local repository (committed changes) are all synchronized.
- Make a change to the README.md file by adding a line with the string “TODO list”. Now, the staging area and the local repository are synchronized with each other but the working directory is not synchronized with them.
- check the differences between the working directory and the staging area (hint: git diff)
- check the differences between the working directory and the local repository (hint: git diff HEAD)
confirm that the changes correspond to what you expected by looking at the diff outputs.
- Add the file README.md to the staging area. Now, the working directory and the staging area are synchronized with each other but they are not synchronized with the local repository.
- check the differences between the staging area and the local repository (hint: git diff –staged)
- check the differences between the working directory and the local repository (hint: git diff HEAD)
confirm that the changes correspond to what you expected by looking at the diff outputs.
- Make an additional modification to the README.md file by adding a line with the string “Add the support email”.
Now, all the three areas working directory, the staging area and the local repository are not synchronized with each other.
- check the differences between the working directory and the staging area (hint: git diff)
- check the differences between the staging area and the local repository (hint: git diff –staged)
- check the differences between the working directory and the local repository (hint: git diff HEAD)
confirm that the changes correspond to what you expected by looking at the diff outputs.
- End of exercise