brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: -C reuses an old commit message, author and date included

Commit
~/tips/tip-commit-reuse-message-c

git commit -C ORIG_HEAD

Commit new content with the message and authorship of an existing commit.

You undid a commit to rework the files, and now you’d have to retype the message. I’d skip that. git commit -C borrows it from any commit you point at.

After a reset, the previous tip of your branch is still available as ORIG_HEAD:

git reset --soft HEAD~1
# change what needs changing, then stage it
git add src/export.js
git commit -C ORIG_HEAD

The new commit gets the old message word for word, and no editor opens. It works with a hash as well, for instance one you found in git reflog or on another branch:

git commit -C 4f2a9c1

If you want the old text as a starting point and plan to edit it, use lowercase -c, which opens the editor with the message filled in.

Know that more than the words come along. The author name and the author timestamp are copied from that commit too, so your new commit can look older than it is, or carry a colleague’s name when you borrow theirs. Add --reset-author to put yourself and the current time on it. And read the message once before you reuse it, because a rework often makes the old description slightly untrue.

Further reading: git-commit documentation

More Commit tips if ! head -n1 "$1" | grep -qE '^[A-Z]'; then git commit --fixup=reword:HEAD~1 git config --global commit.cleanup scissors git commit -m "Fix login redirect" -m "The old code sent signed-out users to a 404." Commit.template pre-fills your commit message All Commit tips (7) All topics

Link