Viewing Commit History
Objective: The objective of this assignment is to familiarize you with Git's commit history and the various commands to view it. You will explore the commit log, examine individual commits, and practice navigating through your project's history.
Instructions:
Part 1: Repository Setup
1. Task 1: Create a new directory/folder on your computer for this assignment and name it "GitCommitHistoryAssignment."
2. Task 2: Navigate to the "GitCommitHistoryAssignment" directory in your terminal or command prompt.
3. Task 3: Initialize a new Git repository in this directory.
4. Task 4: Create a new text file named "README.md" in the repository.
Part 2: Making Commits
1. Task 1: Open the "README.md" file using a text editor or a command-line text editor like Vim or Nano.
nano README.md # Use your preferred text editor
2. Task 2: Add some content to the "README.md" file. For example:
# Git Commit History Assignment
This is the main README file.
3. Task 3: Save the changes to the "README.md" file and exit the text editor.
4. Task 4: Create a new branch named "feature/branch-A."
git branch feature/branch-A
5. Task 5: Switch to the new branch.
git checkout feature/branch-A
6. Task 6: Open the "README.md" file again and add some content specific to branch A.
nano README.md
7. Task 7: Save the changes and exit the text editor.
8. Task 8: Commit the changes in "feature/branch-A."
git add README.md
git commit -m "Add branch-A specific content to README"
Part 3: Viewing Commit History
1. Task 1: View the commit history for the current branch.
git log
Take note of the commit hash, author, date, and commit message.
2. Task 2: Switch back to the main branch.
git checkout main
3. Task 3: View the commit history for the main branch.
git log
Take note of the commit hash, author, date, and commit message.
4. Task 4: Use the `git show` command to view the details of the latest commit on the main branch.
git show HEAD
Take note of the commit details.
5. Task 5: Use the `git diff` command to view the differences between the latest commit on the main branch and the current state of the repository.
git diff HEAD
Take note of any changes.
Solutions
Part 1: Repository Setup
# Task 1
mkdir GitCommitHistoryAssignment
# Task 2
cd GitCommitHistoryAssignment
# Task 3
git init
# Task 4
touch README.md
Part 2: Making Commits
# Task 1
nano README.md # Use your preferred text editor
# Task 2
# Add content to README.md and save
# Task 4
git branch feature/branch-A
# Task 5
git checkout feature/branch-A
# Task 6
nano README.md
# Task 7
# Add content specific to branch A and save
# Task 8
git add README.md
git commit -m "Add branch-A specific content to README"
Part 3: Viewing Commit History
# Task 1
git log
# Task 2
git checkout main
# Task 3
git log
# Task 4
git show HEAD
# Task 5
git diff HEAD