How do you amend the last commit in Git?

How do you amend the last commit in Git?

a) git commit --amend
b) git reset --amend
c) git change HEAD
d) git fix commit

Answer:

a) git commit --amend

Explanation:

The git commit --amend command is used to modify the last commit. This allows you to change the commit message or include additional changes without creating a new commit.

For example, if you forgot to include a file in your last commit, you can stage the file and run git commit --amend to add it to the previous commit.

This command is useful for making minor corrections to your last commit without cluttering the commit history.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top