Generate git COMMIT_EDITMSG text content, but do nothing else

305 Views Asked by At

When you run git commit without the -m flag.... git does all of these things for you:

  1. Generates some content based on the current state of the working dir to display in your editor, with a # prefix on each line, as this info shouldn't go into be in the commit message when you exit your editor
  2. Saves this generated content to a file named COMMIT_EDITMSG
  3. Opens your $EDITOR with the COMMIT_EDITMSG file
  4. When you exit your editor, it immediately commits

Is there a command that simply only does:

  • #1 above
  • And then prints that text content to STDOUT -or- writes it to a custom filename that I specify
  • ...but does nothing else?

I guess there's the option to just run git status and write some text transformation code to insert the # prefixes etc... but if there's just a simple command that does exactly #1 for me, in the exact same format as git commit would have done it, that would be cool.

I need to be able to do this on both Windows + Linux.

1

There are 1 best solutions below

0
On

You can "trick" git-commit to do it for you:

GIT_EDITOR=false git commit ; cat .git/COMMIT_EDITMSG