61.1k views
2 votes
To correct the message of a previous commit in Git, which command is used?

a. git commit -amend
b. git commit -fix
c. git commit -correct
d. git commit -edit

User Yu Shen
by
7.5k points

2 Answers

1 vote

Final answer:

To correct a previous commit message in Git, use the command 'git commit --amend'. It allows you to edit the message or change the commit contents without creating a new commit.

Step-by-step explanation:

To correct the message of a previous commit in Git, the command that is used is git commit --amend. This command allows you to modify the last commit by combining staged changes with the previous commit instead of creating an entirely new commit. This can be used for editing the commit message or even changing the files included in the commit. To use this command, simply run git commit --amend, and then you'll be prompted to edit the commit message in your configured text editor.

User Ryan Warnick
by
8.1k points
0 votes

Final answer:

To correct a previous commit message in Git, use the command 'git commit --amend'. This command should be used carefully as it alters the commit history. Amended commits must be force pushed if they were already pushed to a remote repository.

Step-by-step explanation:

To correct the message of a previous commit in Git, the correct command is git commit --amend. This command allows you to edit the message of the most recent commit. It is important to note that this will create a new commit with a new SHA hash, effectively replacing the old commit. You should use this command with caution, especially if the commit has already been pushed to a remote repository, as it can alter the project's history.

If you simply want to change the commit message, the command would be used as follows:

git commit --amend -m "New commit message"

After amending the commit message, you will need to force push the commit to the remote repository if it was previously pushed. This is done using:

git push origin branch-name --force
User Nadim Younes
by
8.1k points