0
0
Gitdevops~20 mins

Amending the last commit in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Amend Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of amending last commit with new message
What is the output of the following command sequence in a git repository?

git commit --amend -m "Updated commit message"
Git
git commit --amend -m "Updated commit message"
ASuccessfully amended the last commit with the new message.
BError: You have uncommitted changes. Commit aborted.
Cfatal: no changes added to commit (use "git add" and/or "git commit -a")
DError: No previous commit to amend.
Attempts:
2 left
💡 Hint
Amending changes the last commit message or content if staged.
🧠 Conceptual
intermediate
1:30remaining
Effect of amending last commit on commit hash
What happens to the commit hash when you amend the last commit in git?
AThe commit hash changes only if files are added, not if message changes.
BThe commit hash stays the same because only the message changes.
CThe commit hash changes because the commit content or metadata changes.
DThe commit hash stays the same if the commit is pushed already.
Attempts:
2 left
💡 Hint
Commit hash depends on commit content and metadata.
Troubleshoot
advanced
2:00remaining
Error when amending last commit with unstaged changes
You run git commit --amend but get the error:

fatal: no changes added to commit (use "git add" and/or "git commit -a")

What is the cause?
AYou have unstaged changes; git cannot amend without staged changes.
BYour git repository is corrupted.
CYou are trying to amend a pushed commit without force push.
DYou have no previous commit to amend.
Attempts:
2 left
💡 Hint
Amend requires staged changes or message edit.
🔀 Workflow
advanced
2:30remaining
Correct workflow to amend last commit with new file added
Which sequence correctly amends the last commit by adding a new file notes.txt?
Atouch notes.txt<br>git commit --amend --amend
Btouch notes.txt<br>git add notes.txt<br>git commit --amend --no-edit
Cgit add notes.txt<br>git commit -m "Add notes"<br>git commit --amend
Dtouch notes.txt<br>git commit --amend -m "Add notes"<br>git add notes.txt
Attempts:
2 left
💡 Hint
You must stage changes before amending.
Best Practice
expert
3:00remaining
Best practice when amending a commit already pushed to shared repository
You amended your last commit after pushing it to a shared repository. What is the best practice to avoid problems for others?
AAsk all collaborators to reset their branches before you push.
BForce push the amended commit immediately to update the remote branch.
CDelete the remote branch and push the amended commit as new branch.
DAvoid amending pushed commits; instead, create a new commit to fix issues.
Attempts:
2 left
💡 Hint
Rewriting history after pushing can cause conflicts for others.