I regularly run
git commit --only --amend
to reword the commit message of the latest commit I made. This will work irrespective of whether my working directory is clean or not.
Today I noticed that when doing this, the default instructions for writing commit messages shown in my core.editor
include the following comment:
# Clever... amending the last one with dirty index.
Aside from having a bit of an easter egg charm to it, what is this message supposed to tell me? Is it an ironic way of saying that I should be careful when messing with previous commits (esp. if there are staged/unstaged changes present)? And why does it show up even if my working directory is clean?
On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.
Changing the Last Commit: git commit --amend. The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit.
If you commit without using the -m option, git will open your default text editor with a new file, which will include a commented-out list of all the files/changes that are staged in the commit.
"reword" allows you to change ONLY the commit message, NOT the commit contents. "edit" allows you to change BOTH commit contents AND commit message (the mechanism by which git allows you to edit the commit contents is by "pausing" the rebase; so you can amend the commit)
I think this might be the original commit message:
git-commit --amend: two fixes.
When running "git commit --amend" only to fix the commit log
message without any content change, we mistakenly showed the
git-status output that says "nothing to commit" without
commenting it out.
If you have already run update-index but you want to amend the
top commit, "git commit --amend --only" without any paths should
have worked, because --only means "starting from the base
commit, update-index these paths only to prepare the index to
commit, and perform the commit". However, we refused -o without
paths.
Signed-off-by: Junio C Hamano <[email protected]>
I'm not very git proficient, but to me it does look like a genuine compliment for
getting around the dirty index by using --only
without paths
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With