Yesterday, I uploaded a portion of organized wildlife image data to the Github repository, wildlife-in-china.
However, when I checked the git log later, I found that the commit messages I submitted did not follow the commit conventions.
There were a total of 85 commits, and they had already been pushed to the remote Github repository.
I have previously modified individual commit messages, but this time there are too many to change individually.
After some research and experimentation, I have summarized a method for batch modifying Git commit messages.
The main function of the git filter-branch command is to help rewrite the branch history of a Git project.
Here is a detailed usage of the command:
The git filter-branch command provides various options to modify the branch history. Some commonly used options are:
This is the filter for rewriting the commit messages.
The argument is evaluated in the shell with the original commit message on standard input;
its standard output is used as the new commit message.
It's important to note that git filter-branch modifies the commit history, and it can have significant implications if the repository is shared or if there are existing clones.
It is recommended to use this command with caution and communicate with other collaborators to ensure a smooth transition.
Since it is the first time using this command and to prevent any accidental contamination of the entire project, it is advisable to create a dev branch as a means of isolation before proceeding with the experiment.
After that, run git filter-branch to rewrite all commit messages starting with add to feat: add in dev branch.
And check the result with git log
The final step is just switching the git branch from dev to main and repeat the procedure above.
And run git push -f to push these changes to remote Github repository.