Skip to content

How to change commit messages

Thomas Scheffler edited this page Jan 3, 2018 · 3 revisions

Please note: Never, EVER use git push --force on a LTS or the master branch!

Before you do this it's better to clone the branch with --single-branch option.

$ git clone -b {branch} --single-branch https://github.com/MyCoRe-Org/mycore.git {new-location}
  1. On command line, navigate to new created location.

  2. Use the git rebase -i HEAD~n command to display a list of n commits in your default text editor.

     $ git rebase -i HEAD~5 #display a list of last 5 commits
    

The list will look similar to the following:

pick 44169af add tmpdir to maven options
pick 4685d2c use _JAVA_OPTIONS instead
pick 96e6807 isn't needed to set tmpdir
pick 64d41ed fix mycore-pi tests
pick 61c5661 invoke maven build again to prevent parallel tests

# Rebase 72d4c01..61c5661 onto 72d4c01 (5 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
  1. Replace pick with reword before each commit message you want to change

     reword 44169af add tmpdir to maven options
     pick 4685d2c use _JAVA_OPTIONS instead
     reword 96e6807 isn't needed to set tmpdir
     pick 64d41ed fix mycore-pi tests
     reword 61c5661 invoke maven build again to prevent parallel tests
    
  2. Save and close text editor.

  3. In each resulting commit files type now the new message, save the file and close it.

     MCR-1393 Git-Migration use _JAVA_OPTIONS instead
    
     # Please enter the commit message for your changes. Lines starting
     # with '#' will be ignored, and an empty message aborts the commit.
     #
     # Date:      Thu Oct 13 12:44:00 2016 +0200
     #
     # interactive rebase in progress; onto 72d4c01
     # Last commands done (2 commands done):
     #    pick 44169af MCR-1393 Git-Migration add tmpdir to maven options
     #    reword 4685d2c MCR-1393 Git-Migration use _JAVA_OPTIONS instead
     # Next commands to do (3 remaining commands):
     #    pick 96e6807 MCR-1393 Git-Migration isn't needed to set tmpdir
     #    reword 64d41ed MCR-1393 Git-Migration fix mycore-pi tests
     # You are currently editing a commit while rebasing branch 'issues/mycore-2016.06.0.x/MCR-1393-Git-migration' on '72d4c01'.
     #
     # Changes to be committed:
     #       modified:   .travis.yml
     #
    
  4. Now it's time for the push. We need to use --force option.

     $ git push --force
    
Clone this wiki locally