Skip to content

Instantly share code, notes, and snippets.

@natersoz
Last active November 1, 2024 23:38
Show Gist options
  • Select an option

  • Save natersoz/ad529d8963bd0a95ce902adc275843f4 to your computer and use it in GitHub Desktop.

Select an option

Save natersoz/ad529d8963bd0a95ce902adc275843f4 to your computer and use it in GitHub Desktop.
git rebasing and comparisons

Differencing a branch after a Rebase

Let’s say you have a branch. The copy on the server 'origin is up to date with your local branch.
You rebase to main: 

    git rebase main
        
(of course it would be best to do so if your local main is up to date with origin main)
Now, you want to know what changed - only for the working set of files in your branch - when you did the rebase. 
You can do this:

    git diff --stat origin/<branch_name> -- `git diff --name-only main`

What this says is “For all the files I changed with respect to main tell me which ones have changed after I did the rebase”.
And then if you have git difftool set up you can change that command to be:

    git difftool -y origin/<branch_name> -- `git diff --name-only main`
   
And that will use your differencing tool to show the diffs in each of those files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment