Skip to content

UnifiedDiff for staged files with Git #2876

Open

Description

@vogella

The UnifiedDiff compares currently against a file from the workspace. As soon as a file is staged, the comparison falls back to the old compare editor as now two Git states (index vs head) are compared.

The fallback is decided in  CompareUIPlugin.prepareUnifiedDiff(...) . The unified diff needs a workspace file ( IFileEditorInput ) to overlay onto:

if (leftEditorInput instanceof IFileEditorInput) {           // working-tree side
    return new UnifiedDiffSource(..., UnifiedDiffMode.REVERT_MODE, ...);
}
if (rightEditorInput instanceof IFileEditorInput) {
    return new UnifiedDiffSource(..., UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, ...);
}
return null;   // ← neither side is a workspace file → classic compare editor

• Unstaged changes (working tree vs. index/HEAD): the left side is the workspace file → unified diff works. ✅
• Staged changes (index vs. HEAD): both sides are Git revisions, neither is an  IFileEditorInput  →  prepareUnifiedDiff  returns  null  → classic compare. ❌

Not sure how we should handle that. Should we still compare against the workspace file? Or leave that to the old compare?

cc @tobiasmelcher

Activity

  1. tobiasmelcher commented on Aug 11, 2026

    @tobiasmelcher
    Contributor

    Good point, I am aware of this limitation. Can we open a text editor for a Git revision? What is the editor input then? I will take a deeper look when I get time.

  2. iloveeclipse commented on Aug 11, 2026

    @iloveeclipse
    Member

    Can we open a text editor for a Git revision? What is the editor input then?

    Not sure who is meant by "we", but egit can that. If I remember right, it extract the revision to a temp fle outside the workspace. Same with any other revision from the history which is not on disk.

  3. vogella commented on Aug 11, 2026

    @vogella
    ContributorAuthor

    Good point, I am aware of this limitation. Can we open a text editor for a Git revision? What is the editor input then? I will take a deeper look when I get time.

    Current logic, which should also work for Git files:

    File is compared that is changed in working tree -> Equivalent to git diff
    File compared that is staged-> Equivalent to git --cached

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions