usretc
usretc

Reputation: 824

git fixup: get hash of original commit

How does git rebase -i --autosquash know the original commit associated with a fixup? It seems the only "metadata" that git commit --fixup creates is the log message ("fixup!" + original message). The original commit hash is not stored anywhere in the fixup commit (at least, not that I can tell from git show --raw).

So given the fixup commit, how can I find the original commit being fixed?

I'm asking because git rebase still wants you to type a commit hash, even if it should be implied from fixup that I want <original-hash>^; maybe an alias is in order.

Upvotes: 0

Views: 468

Answers (1)

LeGEC
LeGEC

Reputation: 51780

Quoting the doc :

--autosquash
--no-autosquash

When the commit log message begins with "squash! …​" (or "fixup! …​"), and there is already a commit in the todo list that matches the same ..., automatically modify the todo list of rebase -i so that the commit marked for squashing comes right after the commit to be modified, and change the action of the moved commit from pick to squash (or fixup).

[emphasis mine : ]
A commit matches the ... if the commit subject matches, or if the ... refers to the commit’s hash.

As a fall-back, partial matches of the commit subject work, too. The recommended way to create fixup/squash commits is by using the --fixup/--squash options of git-commit[1].

note that "commit subject" means "the first line of the commit message" -- not "the complete commit mesage".

Upvotes: 1

Related Questions