Skip to content

Commit history repeats an older commit and hides new commits when the branch only has a few commits #23234

Done

Description

@NopeKat

The problem

Commit history repeats an older commit and hides new commits when the branch only has a few commits

Description

When a branch has only a couple of commits, the History list can end up stale after a new commit lands: the newest commit never shows up, and the oldest commit is rendered twice. The commit selection and diff follow the same stale data, so clicking the duplicated row shows the wrong changes.

Steps to reproduce

  1. Create a repository and make two commits (e.g. Initial commit and Second commit).
  2. Open the repository and go to the History tab so the list is populated. Because the list is shorter than the viewport, the app immediately loads the next batch.
  3. Create a third commit, either through the app or with git commit while the app is open.
  4. Go back to the History tab (or switch tabs and return).

Expected

Three rows, newest first:

Third commit
Second commit
Initial commit

Actual

Three rows, with the oldest commit duplicated and the new one missing:

Second commit
Initial commit
Initial commit

Cause

_loadNextCommitBatch in app/src/lib/stores/app-store.ts uses the number of already-loaded commits as the skip offset:

newCommits = await gitStore.loadCommitBatch('HEAD', commits.length)
...
commitSHAs: commits.concat(newCommits)

That offset is only valid while HEAD doesn't move. Once a new commit lands, the offset points at a commit that is already in the list, so the old commit is appended again, while the new commit sits before offset 0 and is never loaded.

This is easy to hit with a short history because onScroll in app/src/ui/history/compare.tsx triggers a batch load as soon as commits.length - end <= CloseToBottomThreshold; with two or three commits the whole list is always "close to the bottom", so the stale append happens on every mount. With a longer history the first screen is full and the batch loader isn't reached in that state.

Proposed fix

Before appending a batch, compare the cached history tip (compareState.tip) with the current HEAD. If HEAD has moved, reload the list from the tip via _executeCompare instead of appending. As a safety net, filter appended SHAs against the ones already loaded.

Environment

  • Windows 11 x64
  • GitHub Desktop built from source, release build
  • Electron 44.9.1

Attachments

  • history-small-repo.png — actual rendering with three commits: newest commit missing, oldest commit repeated.
  • history-fixed.png — same flow after the proposed fix: Third / Second / Initial, no duplicates.

Release version

GitHub Desktop 2.7.0

Operating system

Windows 11

Steps to reproduce the behavior

No response

Log files

No response

Screenshots

No response

Additional context

No response

Activity

  1. added
    bug
    priority-3
    on Nov 25, 2026
  2. desktop-triage commented on Nov 25, 2026

    @desktop-triage

    This is a reproducible bug: a clearly reproducible history-duplication defect on short commit lists with explicit repro steps, expected-vs-actual output, and a plausible root-cause pointer to _loadNextCommitBatch. I'm requesting bug and priority-3 (confidence: HIGH on bug, MEDIUM on priority — few users notice this since it self-corrects on a restart/tab switch and only affects branches with very short history). This appears to overlap heavily with #22064 ("After committing on a branch with very few commits, the History view sometimes displays incorrectly"), which already has an open fix PR, #23025 ("Don't overwrite refreshed history with a stale commit batch"); #22064 is not a confirmed closed duplicate, but the symptom (stale/duplicated oldest commit, missing newest commit, self-corrects on restart) and proposed remedy (avoid blindly appending a stale batch when HEAD has moved) match closely enough that this issue and #23025 should be considered together.

    Initial hypothesis

    The reported behavior is consistent with the code path in loadNextCommitBatchReadCore, which computes the batch-load offset from state.compareState.commitSHAs.length rather than from the current HEAD:

    private async loadNextCommitBatchReadCore(
    repository: Repository
    ): Promise<void> {
    const gitStore = this.gitStoreCache.get(repository)
    const state = this.repositoryStateCache.get(repository)
    const { formState } = state.compareState
    if (formState.kind === HistoryTabMode.History) {
    const commits = state.compareState.commitSHAs
    const tip = state.branchesState.tip
    let newCommits: string[] | null = null
    // Prioritize pulling from the local commits if the last one we pulled is local
    if (
    commits.length > 0 &&
    tip.kind === TipState.Valid &&
    gitStore.localCommitSHAs.includes(commits[commits.length - 1])
    ) {
    newCommits = await gitStore.loadLocalCommits(tip.branch, commits.length)
    }
    if (!newCommits || newCommits.length === 0) {
    newCommits = await gitStore.loadCommitBatch('HEAD', commits.length)
    . When a new commit lands after the History list was last populated, that cached length no longer reflects HEAD's actual position, so gitStore.loadCommitBatch('HEAD', commits.length) fetches starting at an offset that re-includes an already-loaded (older) commit while skipping past the newly created one, producing the observed duplicate-oldest/missing-newest rendering. This matches the open PR #23025's premise that a stale commit batch can overwrite freshly refreshed history, so this issue and the #23025 fix should likely be resolved together rather than independently re-investigated.

    Generated by Issue Triage (skills-driven) for #23234 · auto · 41 AIC · ⊞ 4.7K · ◷

  3. added a commit that references this issue on Nov 26, 2026
    bb77c68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions