19

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?

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
  • 3
    @gwho HAHA... I know `git` is capable of a lot of things but GET INTO MY PANTS IT SHALL NOT! ;) – itsjeyd Apr 22 '14 at 09:48
  • This is a GIGANTIC Easter Egg...and just around the time of Easter as well! `git grep -l "Clever... amending the last one with dirty index"` in a clone of [the Git repo](https://github.com/git/git): appears in [`builtin/commit.c`](https://github.com/git/git/blob/master/builtin/commit.c#L1129) and `contrib/examples/git-commit.sh`, as well as what looks like some translation files for other languages. –  Apr 22 '14 at 11:18
  • Line for [`contrib/examples/git-commit.sh`](https://github.com/git/git/blob/master/contrib/examples/git-commit.sh#L279). –  Apr 22 '14 at 11:24
  • I found the commits where the lines were introduced (`git log --oneline -S "Clever... amending the last one with dirty index."` FTW!), [once in April 20th, 2006 by Junio Hamano](https://github.com/git/git/commit/6a74642c500118164ec331da93ef29b1163301bc#diff-47c5bca569d3812821b742f3de274524R379), the other by [Kristian Høgsberg on November 8th 2007](https://github.com/git/git/commit/f5bbc3225c4b073a7ff3218164a0c820299bc9c6#diff-f5dee419d9f7d5a1ab9b0bc413ff9d6eR385). –  Apr 22 '14 at 11:36
  • Not directly related, but apparently there are other Easter Eggs in git as well. I tried the one in [this blog post](http://gal.steinitz.com/blog/2011/06/18/easter-egg-cause-git-to-say-already-up-to-date-yeeah/) but couldn't get it to work. If you do `git grep "Yeeah"` in a clone of the Git repo though, you'll definitely see that the line is still there, even in version 1.9.0. –  Apr 22 '14 at 12:47
  • @Cupcake Thanks for digging up the relevant code parts and commits! Too bad there aren't any *real* hints as to why the authors decided to include that message... – itsjeyd Apr 22 '14 at 17:19

1 Answers1

9

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 <junkio@cox.net>

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

monocell
  • 1,411
  • 10
  • 14
  • +1 Interesting. No hints that the authors think the it's a bad idea to reword commit messages while the index is dirty! :) Doesn't explain why one would want the message to show up with a clean working directory though... – itsjeyd Apr 22 '14 at 17:30
  • 2
    To avoid extra logic I assume. The relevant code seems mostly focused on parsing the arguments given, so I can see why you wouldn't want to check if the index actually was dirty as well... – monocell Apr 22 '14 at 17:41