10

When I add a commit-msg hook which exits with 1 to indicate some error, the original git commit message is gone/not used when I run git commit again.

Is there a way to retain the old commit message so that I do not have to enter the whole message again but just edit the old commit message instead?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Max Rydahl Andersen
  • 3,630
  • 2
  • 23
  • 28
  • 1
    I'm wondering about this too. You can immediately rescue your message from `.git/COMMIT_EDITMSG`, but it would be nice if there's a way to retain the message when the last `git-commit` failed for whatever reason. – 4ae1e1 Dec 29 '15 at 10:10
  • 1
    I wish this question had an answer. I'm looking for the same. For now, I am just showing a big WARNING for the user and suggesting him/her to use `git commit --amend` to edit the commit message. – ricardomenzer Jan 24 '17 at 17:59
  • Possible duplicate of [lost commit message from failed git commit-msg hook](https://stackoverflow.com/questions/52975103/lost-commit-message-from-failed-git-commit-msg-hook) – kelvin Sep 16 '19 at 05:05
  • (Marking this one as the duplicate since the other question already had an answer, as per https://meta.stackoverflow.com/a/252017/10095231) – kelvin Sep 16 '19 at 05:13
  • @4ae1e1 If you're still looking for something more automatic, I posted a wrapper script in the duplicate above. – kelvin Sep 16 '19 at 05:20
  • @ricardomenzer With the wrapper you also can more easily get away with making the hook actually fail the commit. – kelvin Sep 16 '19 at 05:23
  • 1
    @kelvin I've been using [magit](https://magit.vc) as my git client for years now, where I simply `M-p` (`git-commit-prev-message`) in `git-commit` mode to bring back a previous message. No longer a problem for me :-) – 4ae1e1 Sep 22 '19 at 15:55

0 Answers0