This entry is one of the advanced Git interview questions with two distinct responses depending on the context. In case of writing a new commit message from the start, you can utilize the following command.
“git reset -soft HEAD~N &&git commit.”
If you have to edit a new commit message with the addition of existing commit messages, then you should extract the messages and pass them to Git commit. The following command helps in achieving the above-mentioned function.
“git reset -soft HEAD~N &&git commit -edit -m“$(git log -format=%B -reverse .HEAD@{N})”