Module 2: Working with Files & History

Progress: 0%

Module Overview

What You'll Learn

  • Add, edit, and track files
  • View commit history
  • Undo changes safely
  • Compare file changes

Time Estimate

35-50 minutes

Prerequisites

Module 1: Git Basics

File Operations

Adding Files

Track new files in your repository:

git add filename.txt

Add a specific file to staging area

git add .

Add all modified files to staging area

Editing Files

Make changes to your files and track them:

git status

Check which files have been modified

Removing Files

Remove files from tracking:

git rm filename.txt

Remove file from repository and staging area

Viewing History

Commit History

Explore your repository's commit history:

git log

View detailed commit history

git log --oneline

View compact commit history

File History

Track changes to specific files:

git log --follow filename.txt

View history of a specific file (including renames)

Undoing Changes

Unstaging Changes

Remove files from staging area:

git reset HEAD filename.txt

Unstage a specific file

Discarding Working Directory Changes

⚠️ Warning: This permanently discards changes!

git checkout -- filename.txt

Discard changes to a specific file

Reverting Commits

Create a new commit that undoes previous changes:

git revert HEAD

Revert the last commit

Comparing Changes

Working Directory vs Staging

See what changes are not yet staged:

git diff

Show unstaged changes

Staging vs Last Commit

See what changes are staged for commit:

git diff --staged

Show staged changes

Comparing Commits

Compare changes between different commits:

git diff HEAD~1 HEAD

Compare current commit with previous commit

Module Quiz

Test your understanding of file operations and history:

1. What command shows the difference between working directory and staging area?

2. How do you safely discard changes to a file in the working directory?

3. What does git log --oneline do?

4. Which command removes a file from Git tracking but keeps it in the working directory?

Quick Navigation