Skip to content

fix: /diff shows changes since the most recent message, not the previous one#5394

Open
nolanchic wants to merge 1 commit into
Aider-AI:mainfrom
nolanchic:fix/cmd-diff-since-last-message
Open

fix: /diff shows changes since the most recent message, not the previous one#5394
nolanchic wants to merge 1 commit into
Aider-AI:mainfrom
nolanchic:fix/cmd-diff-since-last-message

Conversation

@nolanchic

Copy link
Copy Markdown

Problem

/diff (and the diff aider auto-shows after each commit) displayed changes accumulated since the previous message instead of the current one, once two or more messages had been processed in a session.

raw_cmd_diff used commit_before_message[-2] as the diff base. But commit_before_message is appended exactly once per top-level message (in init_before_message, before the message is processed), so:

  • [-1] = head recorded before the most recent message (correct base for "diff since the last message")
  • [-2] = head recorded before the previous message (what the code used)

The sibling method show_undo_hint already uses [-1], so the two disagreed.

There was a second, related defect on the same path: the len(...) < 2 fallback used current_head + "^", which only goes back a single commit. For a message that produced multiple commits (e.g. via reflections), that showed just the last reflection's diff rather than the whole message's changes.

Fix

aider/commands.pyraw_cmd_diff:

if not self.coder.commit_before_message:
    commit_before_message = current_head + "^"
else:
    commit_before_message = self.coder.commit_before_message[-1]

This matches show_undo_hint (base_coder.py), and only falls back to current_head + "^" when no message has been recorded yet (empty list).

Test plan

  • Added test_cmd_diff_since_last_message_not_previous — builds three commits C0 -> C1 -> C2, sets commit_before_message = [C0, C1] (HEAD = C2), and asserts /diff produces the C1..C2 diff (not C0..C2). Fails on main, passes with the fix.
  • pytest tests/basic/test_commands.py — 71 passed (incl. the existing test_cmd_diff).
  • pytest tests/basic/ -k "diff or undo or commit" — 30 passed.
  • pre-commit run --files aider/commands.py tests/basic/test_commands.py — isort / black / flake8 / codespell all pass.

…ous one

raw_cmd_diff used commit_before_message[-2] as the diff base, but that
entry is the head recorded before the PREVIOUS message. Once two or more
messages had been processed in a session, /diff (and the auto-shown
post-commit diff) displayed changes accumulated since the previous message
rather than the current one. For messages that produced multiple commits
(reflections), the old `current_head + "^"` fallback only went back a
single commit, so it showed just the last reflection's diff.

Use commit_before_message[-1] (matching show_undo_hint) and fall back to
`current_head + "^"` only when no message has been recorded yet.

Adds a regression test.
@CLAassistant

CLAassistant commented Jul 4, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants