Sublime Forum

Editing Commit Messages

#1

How exactly does editing commit comment work from SM2?

What is the equivalent command, git?

After changing the commit comment, SM2 displays the date and time the comment was edited, instead of the date and time of the original commit.

Is it possible to change this behavior?

After changing the commit comment, the reflog command displays the original commit comment. Is this to be expected?

Greeting.

1 Like

#2

It could be using git commit --amend or a git rebase operation, depending on where commit is in the commit graph (though I suspect that for simplicity it might always be using git rebase).

In any case, regardless of which command it does it, altering anything about a commit creates a whole new commit object (which is why the rebase is needed).

I believe with the right git-fu you can modify things like the author and commit time as a part of the rebase, but I don’t think Merge has any facility to do that out of the box.

0 Likes

#3

I’m fairly certain all operations in the Edit Commit menu uses git rebase internally. However, as @OdatNurd mentioned, you can use git commit --amend to modify the most recent commit message or git rebase -i to edit commit messages prior.

I think you’re talking about the Edit Commit -> Edit Commit Contents option which has an existing bug report:

0 Likes

#4

Hi all,

Thanks for sharing this question!

Editing a commit will create an entirely new commit based on the previous commit (due to the way Git works - commits are immutable objects).

Sublime Merge will display the original commit creation date, along with the most recent commit date (the date it was last edited). This is consistent with how Git stores and displays these objects.

The only exception here is “Edit Commit > Edit Commit Contents…”.
Due to the way this is implemented, the original commit date will not be preserved.
As @srbs mentioned, there’s an existing issue request tracking this.

Thanks,
- Dylan

0 Likes

#5

Thank you all for responding.

I am translating this (I do not speak English), so I am having difficulty communicating clearly what I am trying to describe.

Apologies.

I will try to improve my questions, with a practical example.

I am using a local, non-cloned repository created with git init; when you clone a repository the logs from the git reflog command are removed.

git version 2.29.2.windows.2

In SM2, you can edit a commit message by simply doing (responding to @srbs):

Edit Commit -> Edit Commit Message

Change the message and do enter, well, it looks great!!!

Now if you do via git reflog console, you discover that the original commit message is there, instead of seeing the new one. Also, maybe the best thing is that git reflog, shows nothing has changed.

I say this “maybe best” because, I only changed the message, not the content of the commit, so why make a fuss.

But the point here is, that the new message is not displayed by the git reflog command.

If you use git log, now you see the new commit message, which was edited with SM2.

Also if you use the git shortlog command, you can also see the new message that put the commit of your interest.

But also, you can see the date and time of the original commit, just before modifying the commit message with SM2.

However, SM2 shows the date of issue of the Commit Message, in the commit tree.

Instead of the date the commit was made.

In fact, SM2 adds the edit date of the message alongside the original commit date.

image

As @OdatNurd says a new commit “is born”, you can notice this immediately in SM2, a different Commit Hash is shown, as well as via console.

But if a new commit it is created or born when editing your message:

Why is the date and time of the original commit visible in SM2 and via console?

There is still a little more…

You can edit a commit message, further back in time, using the command git rebase -i head~x

For example: git rebase -i head~7

The default editor indicated in the git configuration will open.

You will have to replace in the line of interest, to modify the commit message, [ pick ] by [ reword ] and save the changes and close the editor.

Then the editor will open again, with a single line, containing the commit message, there you write the new message for the commit, save the changes and close the editor.

Now via console run git reflog, you will see a lot of new information, which records your edit of the commit message.

Now if you load the repo into SM2, you will of course see the new commit message.

You will also see the new message for your commit, doing git log and git shortlog.

Because of all this, I wonder, how the hell SM2 changes the message of a commit, further back in time, of the most recent commit.

So I asked, what is the equivalent command.

On the other hand…

Also SM2, in the commit tree, shows the date of the commit message, and this is propagated from the bottom (old commit with its modified message) to the last commit made.

I understand that this must be by design of git, since when using rebase from the console, SM2 shows the same behavior.

But as it is, when modifying a message from an old commit, in SM2, it ended up seeing how it modified all the commits in the same second, until the last commit made.

I think this deserves an option to change the behavior of SM2, in the SM2 commit tree, to show the date of the commits, instead of the edit date of the commit message.

The latter is at the cost of exploiting the bug in git, that despite generating a new commit, when modifying its message, the date of the original commit remains.

Greeting.

0 Likes

#6

Hi @null,

Thank you for sharing these questions! I’m going to address each question below:

Why is the new commit message not in the reflog?
The reflog stores a historical list of actions (such as committing, checking out etc). Therefore, the commit message will never change in the reflog as the history of the reflog is immutable - you can only add to the reflog.

When you edit a commit in Sublime Merge, you’ll see a reflog entry appear titled “amend”, indicating that a commit was amended (edited).

Why is the original commit date preserved?
This is the default behavior of Git - if you ever edit a commit, the original commit metadata will be preserved. This is important for many reasons, one of them being historical purposes.

Consider the workflow where one engineer implements a feature, and then another engineer edits the commit message. You definitely want to keep the original author information, but you also want to indicate that it was edited (committed) by someone else.

What command do we use to edit commit messages?
Edit: we use a combination of Git plumbing commands and rebase functionality.

I appreciate the feedback regarding dates displayed in the commit graph. When you have a spare moment, it would be great if you could share an enhancement request for this at: https://github.com/sublimehq/sublime_merge/issues/new/choose

Thanks,
- Dylan

0 Likes

#8

Thanks for your answers @Djohnston

Regarding the first answer.

I understand that git reflog only adds things to the history, as you explain.

What I want to indicate here is that when you change the commit message from SM2, no logs of that change are shown via git reflog, that is, it does not add information about the commit message change.

Also, git reflog shows the old message from the commit, not the new one.

This is not right, I think this is clear.

You can experience what I am trying to indicate.

  1. Install git on windows.
  2. Indicate the path of the git binary in SM2, for example c:\program files\git\bin\git.exe
  3. Initialize a repository.
  4. Generate some commits with SM2.
  5. Change the oldest commit message via SM2.
  6. Run git reflog.

You shouldn’t see the new commit message, nor should you see any edit change information.

If you or someone else can notice what I say, then it is not that it only happens in my case.

If this is so, it clearly needs attention, I don’t think it’s good for SM2 to behave differently from a developer, I would use git via console.

I also understand that SM2, use git at low level; I think that’s what you more or less say.

However, I think that SM2 should tell the user that what they are about to do (eg edit a commit message) with the git database is not playable via ordinary git commands.

Since, the reflog log does not reflect the changes when using SM2. On the contrary, if you change the message of a commit, via git console, the modification logs will be displayed by git reflog.

Regarding the second answer.

When you say, the original commit metadata is preserved; Now I understand. I was clearly missing that information. Thank you!

Regarding the third answer.

I want to clarify a point (I don’t know, if I was clear enough), in the commit graph in SM2;

Whether modifying a commit message via SM2 or via git console.

SM2, propagates the edit date of the commit message, from bottom to top, in the commit panel or graph. Not that this only happens when using SM2.

Sorry, this last point refers to enhancement request?

Greeting.

0 Likes

#9

Hi @null,

Thank you for the additional information.
If I understand correctly, you’re asking for more a more descriptive reflog entry when editing a commit via Sublime Merge (amend: my new message rather than a plain amend entry)?

This may not be possible due to limitations in Git plumbing commands, though I still encourage you to submit this feedback via the official issue tracker and we can definitely investigate any available improvements.

regarding your second point, that’s definitely intended behavior as we’re just displaying what Git stores internally. I can understand only wanting to see the original creation date in the commit graph too, so I’d definitely be open to a preference here. I’d definitely encourage you to submit an enhancement request :slight_smile:

Thanks for sharing your feedback with the team!

Kind regards,
- Dylan

0 Likes