0

A change involved both restructuring file locations and modifying file content. Following the advice of this answer to ensure that git interprets my git mv changes as rename rather than delete/create, I split the change into two separate commits.

commit 70c9cf5ab06b1838b1b7c4b8278728bedbaecbf5 (HEAD -> main)
Author: Michael Moreno <michaelmoreno.dev@gmail.com>
Date:   Fri Apr 7 22:44:01 2023 -0600

    :classical_building: `arch` Character,Item ⊃ Entity ⊃ StateMachine :diamond_shape_with_a_dot_inside: `add` Effect/Immunity/Spell system

commit 62a0309e8dd083af9ba2d76ff1ed0614ff33a851
Author: Michael Moreno <michaelmoreno.dev@gmail.com>
Date:   Fri Apr 7 07:55:02 2023 -0600

    :exclamation::recycle: `env` mv characters/ items/ into entities/

Since the earlier commit was auxiliary to the later, I would like to add a reference to the later commit in the older commit's message body

Like so


    :exclamation::recycle: `env` mv characters/ items/ into entities/

    WARNING: Not a standalone commit, auxiliary to 70c9cf5.

I attempt to do this using

git rebase -i 62a0309e8dd083af9ba2d76ff1ed0614ff33a851^

and marking the commit with reword, but when I save the new commit message it appears to regenerate a new commit id for the later commit (no longer 70c9cf5), and when pushed GitHub shows

This commit does not belong to any branch on this repository, and
may belong to a fork outside of the repository.

Running git log shows an entirely new commit id for the most recent commit.

Is there a way to refer to recent commits in the message body of older commits without resulting in the recent commit id to be generated?

Michael Moreno
  • 947
  • 1
  • 7
  • 24

1 Answers1

1

Is there a way to refer to recent commits in the message body of older commits without resulting in the recent commit id to be generated?

Not with the exact commit id. Just refer to it as "the next commit" or "a following commit" and include the commit message.

Pre-calculating the resulting commit id is impossible since the commit among other things is based on the time of date when it is created. You could possibly refer to the git tree object which should stay the same, but that is not a particular useful reference for anyone reading the history later.

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Alright, thanks. One question though: The commit id still shows up hyperlinked in the GitHub commit, allowing me to click on it which actually shows me the original commit. https://github.com/michaelmoreno/ai-rpg/commit/1d61b75571e4879e594c8861b66afd428466c8e1 and I'm still able to do `git checkout` at the id. How can I remove it? I don't want duplicate stores like that cluttering my git history. – Michael Moreno Apr 08 '23 at 09:18
  • 1
    "Loose" commits like that are a normal thing in git and is the result of rebase, branch deletion and similar operations. Git will eventually garbage collect such commit (after a month by default I think). You can force a garbage collect with `git gc`. – hlovdal Apr 08 '23 at 09:37