0
0
Gitdevops~15 mins

Amending the last commit in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Amending the Last Commit in Git
📖 Scenario: You are working on a project and just made a commit with a small mistake in the commit message. You want to fix this mistake without creating a new commit.
🎯 Goal: Learn how to amend the last commit message using Git commands.
📋 What You'll Learn
Create a file named example.txt with specific content
Add the file to the Git staging area
Make an initial commit with a given message
Amend the last commit message to the correct one
Display the final commit message to verify the change
💡 Why This Matters
🌍 Real World
Fixing mistakes in commit messages is common when working on software projects to keep history clean and understandable.
💼 Career
Knowing how to amend commits helps developers maintain clear project history and collaborate effectively in teams.
Progress0 / 4 steps
1
Create a file and add content
Create a file named example.txt and add the text Hello, Git! inside it.
Git
Need a hint?

Use the echo command to write text into a file.

2
Add the file to Git staging area
Initialize a new Git repository and add the file example.txt to the Git staging area using the git init and git add commands.
Git
Need a hint?

Use git init followed by git add example.txt to initialize the repository and stage the file.

3
Make the initial commit
Make an initial commit with the message Initial commit with typo using git commit -m.
Git
Need a hint?

Use git commit -m "Initial commit with typo" to commit.

4
Amend the last commit message
Amend the last commit message to Initial commit with correct message using the git commit --amend -m command. Then, display the last commit message using git log -1 --pretty=%B.
Git
Need a hint?

Use git commit --amend -m "New message" to change the last commit message.

Use git log -1 --pretty=%B to show the last commit message.