Skip to content

gert::git_diff != git diff #152

Open

Description

@assignUser

I was looking for git diff in gert two compare to refs .
I found git_diff which can only display the changes in the passed ref, which is the most basic function of git diff.

Is there a way to compare two refs (e.g. two branches) with gert and find the changed files between them (git diff --name-only branch1 branch2)?

Activity

  1. jeroen commented on Aug 30, 2021

    @jeroen
    Member

    git_diff() returns a data frame, with a column containing the file name for each change? For example:

    git_diff('HEAD^')$new

    Shows the files changed in your most recent commit.

  2. assignUser commented on Aug 30, 2021

    @assignUser
    Author

    Right. But only files changed in this commit. (or current working dir vs. last commit)

    Not the changed files between two commits as you would with git diff ref1 ref2 -- (--name-only just for better readability):

    $> git diff --name-only main run-on-change --
    API
    NAMESPACE
    R/core.R
    R/source.R
    R/utils.R
    inst/script.R
    man/add_lib_dirs.Rd     
    man/benchmark_run_ref.Rd
    tests/testthat/test-utils.R

    I am looking for this behaviour because I want to run some tests/benchmarks on pull requests only if the relevant file has changed between the branches (e.g. main and devel), so it would not be enough to only check the files changed in the last/one specific commit.

    For now I can use system but I would rather use your great package to do it within R 😃

    edit: And thank you for your quick response!

  3. gadenbuie commented on Oct 16, 2025

    @gadenbuie

    I'm working on adding git support to btw (i.e. tools for LLMs) using gert, and as requested here it would be very helpful for git_diff() to be able to provide a unified diff between two arbitrary refs.

    An interface like this would be awesome:

    git_diff("main..run-on-change") # shows unified diff of changes in run-on-change branch
    git_diff("HEAD~2..HEAD") # shows unified diff of the last three commits

    In other words, I'm thinking of something similar to GitHub's /compare endpoint with ref_base..ref_compare syntax.

    Alternatively, it could be a new function, git_diff_compare():

    git_diff_compare(base = "main", compare = "run-on-change")
    
    # or
    git_diff_compare(ref_base = "main", ref_compare = "run-on-change")
    
    # or
    git_diff_compare(start = "main", end = "run-on-change")

    Without this, git_diff() is limited to returning the diff of a single commit, i.e. git_diff("run-on-change") shows the diff of the last commit in the run-on-change branch, which is useful but limited.

  4. maelle commented on Apr 10, 2026

    @maelle
    Collaborator

    @gadenbuie would you want to open a PR? 😸

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

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions