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→