Search code examples
gitchangelog

How to start using automatically generated changelog with old commit history present


In a company, we have a project that we are working on for some time already. In this project we use git for versioning. We are trying to make our git workflow more professional and more easy to collaborate. One of the steps we want to take is automatically generate a changelog, e.g. with generate-changelog. This package requires that the commits our formatted following the Angular commit message format.

I will be happy to write all the commits in the future following this format, but we still have a lot (a couple of hundreds) of commits that do not follow this format. In the meanwhile, I want to have the changelog generated automatically.

Is there a way to generate the changelog automatically, although old commit messages do not follow the required format? Or could we possibly 'update' the commit message such that we do follow the required format?

In case you need more info, let me know and I will update the question accordingly.

Update: I want to prepend all old commit messages with some text like: docs:. Interactive rebase as suggested here and in the answer below does work, but only if you have a few commit messages. I am looking for a way to change all commit messages at once. An exmaple that I did not get to work yet can be found in this SO question/answer.


Solution

  • Well, considering you don't want to write a changelog file for your actual history, the option would be change old commit messages.

    As explained in the linked answer you should run git rebase -i HEAD~n, where n is the number of commits you want to change. The --root flag can be used instead of HEAD~n to choose the whole history in the rebase command, as shown here:

    git rebase -i --root
    

    During the interactive rebase you will see each of selected commits in one line. And since you just want to rewrite its messages you can flag its line with the reword keyword, changing equivalent commit message as your desire

    After that, save your changes and run generate-changelog to get your automatic changelog file