2025-09-02 07:07:15 +00:00
|
|
|
|
z1
|
2025-09-02 07:32:18 +00:00
|
|
|
|
z2
|
2025-09-02 08:23:36 +00:00
|
|
|
|
Sure! Below are simplified instructions for the topic **2.2 Git Basics – Recording Changes in the Repository**.
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
# 2.2 Recording Changes in Git
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
## Goal
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
You will learn to:
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
* Check the repository status
|
|
|
|
|
|
* Add files to staging area
|
|
|
|
|
|
* Commit changes
|
|
|
|
|
|
* View differences
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
## Glossary
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
* **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
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
## Key Commands
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
### 1) Check status
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
git status
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
### 2) Add to staging area
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:36 +00:00
|
|
|
|
git add filename
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
### 3) View differences
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
* **Changes not in staging area**:
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
git diff
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
* **Changes in staging area**:
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:33 +00:00
|
|
|
|
git diff --staged
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
### 4) Commit changes
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:36 +00:00
|
|
|
|
git commit -m "Description of changes"
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
## Simple workflow
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
1. **Check status**: `git status`
|
|
|
|
|
|
2. **Add to staging area**: `git add <file>`
|
|
|
|
|
|
3. **Commit**: `git commit -m "Description"`
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
## Exercise (10 min)
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
1. **Create a repository**
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
git init git-lesson
|
|
|
|
|
|
cd git-lesson
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
2. **Create and commit a file**
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:36 +00:00
|
|
|
|
echo "Hello Git!" > README.md
|
2025-09-02 07:03:49 +00:00
|
|
|
|
git add README.md
|
2025-09-02 08:23:36 +00:00
|
|
|
|
git commit -m "Add README"
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
3. **Modify the file**
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:36 +00:00
|
|
|
|
echo "Second line" >> README.md
|
2025-09-02 08:23:33 +00:00
|
|
|
|
git status
|
|
|
|
|
|
git diff
|
|
|
|
|
|
git add README.md
|
2025-09-02 08:23:36 +00:00
|
|
|
|
git commit -m "Add second line"
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-09-02 08:23:36 +00:00
|
|
|
|
4. **Check history**
|
2025-09-02 07:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-09-02 08:23:33 +00:00
|
|
|
|
git log --oneline
|
2025-09-02 07:03:49 +00:00
|
|
|
|
```
|