Search code examples
gitcommitgit-committodo

How to copy the message of the previous commit into the new commit to edit it


I write my commits in the following way, namely I try to document what has been done and what remains to be done (todo list):

Done: 
- task1 done
Todo: 
- task2
-- implement feature1
-- implement feature2
- task3
-- implement feature1
-- implement feature1

Is there a way to automatically copy the content of the previous commit into the new commit to edit (in my case, could be interesting for the todo list)

If someone have another system of "todo list" integrated with git, I am also happy to hear


Solution

  • Is there a way to automatically copy the content of the previous commit into the new commit to edit (in my case, could be interesting for the todo list)

    Sure. Look at the -C and -c arguments to git commit:

    -C <commit>, --reuse-message=<commit>

    Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.

    -c <commit>, --reedit-message=<commit>

    Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.

    If you want to make a new commit that re-uses the messages from the current HEAD commit, just run:

    git commit -c HEAD
    

    Or if you want to minimize typing:

    git commit -c@
    

    (Because @ is another name for HEAD.)