QA
Beginner LevelGit & GitHub

How do you modify the last commit message or add staged files using git commit --amend?

❓ Interview Prompt: Explain git commit --amend, replacing the most recent commit on your active branch, and rewrite risks on pushed commits.

git commit --amend replaces the most recent commit on your active branch with a new commit containing newly staged files or an updated message. Never amend commits that have already been pushed to shared remote branches!

Code Implementation Example

bash
git add src/config.js
git commit --amend --no-edit
git commit --amend -m "feat(auth): complete JWT validation implementation"
💡Amending the last commit with newly staged files and updated message.
🎯 Interview Key Takeaway

Use git commit --amend to fix typos or add forgotten files to the last local commit before pushing.

#git commit --amend#History Editing#Beginner
Back to all Git & GitHub Questions→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?