2

My git workflow goes like this:

git add . 
git commit 
git push

I would like to know if there are git commands that let me accept the autogenerated commit message (after removing the # of course). The closest answer I've found is this, but it gives me the error:

Aborting commit due to empty commit message.

I can probably change my editor in .gitconfig to a python script that accomplishes this but I'd like to not do that as it will be a system-wide change.

Gino Mempin
  • 12,644
  • 19
  • 50
  • 69
Nachiket
  • 459
  • 3
  • 12
  • 1
    The resolution in the linked question in combination with a [`prepare-commit-msg` hook](https://git-scm.com/book/pl/v2/Customizing-Git-Git-Hooks) might work. – tkausl Nov 30 '20 at 13:06
  • 1
    You also have a .git/config [that is local your repo](https://stackoverflow.com/a/8801759/2745495). – Gino Mempin Nov 30 '20 at 13:11
  • @GinoMempin Thanks but suffers from the same drawback, I'd like to use the automatically generated message sometimes, and sometimes I'd like to edit it. I'd ideally like to make two scripts which pass different flags to git – Nachiket Nov 30 '20 at 13:18
  • The default auto-generated commit message to `git add .` + `git commit` is a blank line followed by comments "*Please enter the commit message for your changes. ...*" then "*On branch ... Your branch is up to date..." then a "*Changes to be committed*" list. You want to auto-remove the comment markers and auto-accept that? Or does this include the `git add .` after a rebase or merge? – Gino Mempin Nov 30 '20 at 13:26
  • Just want to auto-remove the comment markers and accept that. No rebases or merges or anything like that. – Nachiket Nov 30 '20 at 13:30
  • 1
    The default commit message is *never* a good one. It's either neutral (useless) or actively bad. So you can just replace it with a fixed, useless commit message. It's better to put in an actual message though. – torek Nov 30 '20 at 18:22

1 Answers1

1

Yes, there is such an option to git commit, --allow-empty-message. That will bypass this check and allow you to make a commit without making a meaningful change to the commit message.

However, as many people have mentioned in the comments, this is not, in general, a good idea. In almost all cases, you will want to provide a helpful message both for other project participants as well as future you. Unless you are writing an automated script, providing a helpful commit message is a best practice.

If your particular case is that you don't want to write a commit message for a merge, then simply set GIT_MERGE_AUTOEDIT=no in the environment and Git won't prompt for one.

bk2204
  • 31,903
  • 3
  • 22
  • 39