103 lines
1.4 KiB
Plaintext
103 lines
1.4 KiB
Plaintext
z1
|
||
z2
|
||
Sure! Below are simplified instructions for the topic **2.2 Git Basics – Recording Changes in the Repository**.
|
||
|
||
# 2.2 Recording Changes in Git
|
||
|
||
## Goal
|
||
|
||
You will learn to:
|
||
|
||
* Check the repository status
|
||
* Add files to staging area
|
||
* Commit changes
|
||
* View differences
|
||
|
||
---
|
||
|
||
## Glossary
|
||
|
||
* **Tracked** – file was in the last commit
|
||
* **Untracked** – new file for Git
|
||
* **Staging area** – list of changes that will go into the next commit
|
||
* **Commit** – saved snapshot of the project
|
||
|
||
---
|
||
|
||
## Key Commands
|
||
|
||
### 1) Check status
|
||
|
||
```bash
|
||
git status
|
||
```
|
||
|
||
### 2) Add to staging area
|
||
|
||
```bash
|
||
git add filename
|
||
```
|
||
|
||
### 3) View differences
|
||
|
||
* **Changes not in staging area**:
|
||
|
||
```bash
|
||
git diff
|
||
```
|
||
|
||
* **Changes in staging area**:
|
||
|
||
```bash
|
||
git diff --staged
|
||
```
|
||
|
||
### 4) Commit changes
|
||
|
||
```bash
|
||
git commit -m "Description of changes"
|
||
```
|
||
|
||
---
|
||
|
||
## Simple workflow
|
||
|
||
1. **Check status**: `git status`
|
||
2. **Add to staging area**: `git add <file>`
|
||
3. **Commit**: `git commit -m "Description"`
|
||
|
||
---
|
||
|
||
## Exercise (10 min)
|
||
|
||
1. **Create a repository**
|
||
|
||
```bash
|
||
git init git-lesson
|
||
cd git-lesson
|
||
```
|
||
|
||
2. **Create and commit a file**
|
||
|
||
```bash
|
||
echo "Hello Git!" > README.md
|
||
git add README.md
|
||
git commit -m "Add README"
|
||
```
|
||
|
||
3. **Modify the file**
|
||
|
||
```bash
|
||
echo "Second line" >> README.md
|
||
git status
|
||
git diff
|
||
git add README.md
|
||
git commit -m "Add second line"
|
||
```
|
||
|
||
4. **Check history**
|
||
|
||
```bash
|
||
git log --oneline
|
||
```
|