Trying to edit last commit message by appending a string in the end of the previous message.
Trying to do this from a CI server, so I'm looking for an automatic solution that doesn't require any interactive human intervention
Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.
You can change the most recent commit message using the git commit --amend command.
Changing the latest Git commit message If the message to be changed is for the latest commit to the repository, then the following commands are to be executed: git commit --amend -m "New message" git push --force repository-name branch-name.
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.
If you want to amend the current commit and change the commit message without opening an editor, you can use the -m
flag to supply a message. For example:
git commit --amend -m"This is the commit message."
Will amend the current HEAD, using the message given as the new message:
% git log
commit adecdcf09517fc4b709fc95ad4a83621a3381a45
Author: Edward Thomson <[email protected]>
Date: Fri Mar 17 12:29:10 2017 +0000
This is the commit message.
If you want to append the message, you'll need to fetch the previous one:
OLD_MSG=$(git log --format=%B -n1)
And then you can use that to set the new message, using multiple -m
's to set multiple lines:
git commit --amend -m"$OLD_MSG" -m"This is appended."
Which will append the given message to the original:
% git log
commit 5888ef05e73787f1f1d06e8f0f943199a76b70fd
Author: Edward Thomson <[email protected]>
Date: Fri Mar 17 12:29:10 2017 +0000
This is the commit message.
This is appended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With