0
0
Gitdevops~5 mins

Amending the last commit in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the command git commit --amend do?
It lets you change the last commit by adding new changes or editing the commit message without creating a new commit.
Click to reveal answer
beginner
How can you change only the commit message of the last commit without changing files?
Run git commit --amend without staging new changes. This opens the editor to edit the message.
Click to reveal answer
intermediate
True or False: Amending a commit changes the commit's unique ID (hash).
True. Amending creates a new commit with a new ID because the commit content changes.
Click to reveal answer
intermediate
Why should you be careful when amending commits that have already been pushed to a shared repository?
Because it rewrites history and can cause problems for others who pulled the original commit.
Click to reveal answer
beginner
What is the difference between git commit --amend and creating a new commit?
Amending changes the last commit itself, while a new commit adds a separate change on top of the history.
Click to reveal answer
What happens if you run git commit --amend after staging new changes?
AThe staged changes are discarded.
BA new commit is created without changing the last commit.
CThe last commit is replaced with a new commit including the staged changes.
DGit shows an error and stops.
Which command lets you edit the last commit message without changing files?
Agit commit --amend
Bgit commit --fix
Cgit commit --edit
Dgit commit --message
Why is it risky to amend commits that have been pushed to a shared repository?
AIt locks the repository for others.
BIt deletes the repository.
CIt automatically merges conflicts.
DIt can confuse others because the commit history changes.
What is the effect on the commit ID when you amend a commit?
AThe commit ID changes because the commit is new.
BThe commit ID stays the same.
CThe commit ID is deleted.
DThe commit ID duplicates.
If you want to add forgotten changes to your last commit, what should you do?
ARun <code>git commit</code> without options.
BStage the changes and run <code>git commit --amend</code>.
CRun <code>git reset</code>.
DDelete the last commit.
Explain how to safely amend the last commit message without changing any files.
Think about the steps to change only the message.
You got /4 concepts.
    Describe the risks of amending commits that have already been pushed to a shared repository and how to avoid problems.
    Consider teamwork and shared history.
    You got /5 concepts.