Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff between branches #255

Open
franksands opened this issue Nov 22, 2018 · 20 comments
Open

Diff between branches #255

franksands opened this issue Nov 22, 2018 · 20 comments
Assignees
Labels
commit list An issue related to the commit list enhancement New feature or request

Comments

@franksands
Copy link

franksands commented Nov 22, 2018

Problem description

Depending on the project, the commit tree can get very long and it can be difficult to find the last commit of a branch. This makes it difficult to compare the current branch to another branch

Preferred solution

A new command "Diff with another Branch". This command would list the available branches, just like "Checkout Branch". When the branch is selected, the app would display a diff between the HEAD of the current branch with the HEAD of the selected branch

Alternatives

A way to filter the commit list so that selecting two far apart commits easier.

@srbs
Copy link

srbs commented Nov 24, 2018

I have a workaround for you:

Let's say you wanted to diff the branches master & release/1.0. In the location bar:

  1. Alt + click the eye next to master to hide all branches but master
  2. click the eye next to release/1.0 to also show this branch

Now you can visually see just the changes in both branches and easily diff the two since one is at the top of the list.

(Shamelessly copied & modified from myself here)

@franksands
Copy link
Author

Thanks, that a great workaround, very similar to my proposed alternative. I still think the command works be useful and simpler.

@wbond wbond added enhancement New feature or request commit list An issue related to the commit list labels Jan 2, 2019
@acharron
Copy link

acharron commented Jun 5, 2019

It may sound silly, but I've spent 30 minutes trying to find a "Diff" or "Compare" command in the command palette, right clicking on commits in every combination possible, trying every search pattern I could think of. (I'm adding details for others coming here after looking up "sublime merge diff branches")

I didn't realize that selecting 2 commits ( Ctrl + click ) displays the diff between them.
So, to complete @srbs steps for dummies like me:

  1. Alt + click the eye next to master to hide all branches but master
  2. click the eye next to release/1.0 to also show this branch
  3. Click the last commit of the first branch (i.e. master)
  4. Ctrl + click the last commit of the second branch (i.e. release/1.0) to select both commits at the same time
  5. The diff is displayed on the right (in the commit info lines you will see "Commit Hash" "Tree" "Diffing from" on top of Author, Date, etc.)

The workaround effectively solves the problem, although a command could be useful. I would see the implementation working as follow: (just an idea)

  1. Hide all branches except the 2 concerned by the diff
  2. Select both commits at the tip of each branch
  3. In the commit list, hide the intermediary commits to make it obvious which 2 commits are currently selected if both tips are not visible. Hide the intermediary commits with a "...." icon, that can be clicked to reveal the full list.

@pwinston
Copy link

pwinston commented Jul 4, 2019

Maybe I'm missing something, but if the branches are "far apart" with many commits in between, then I can't see the tip of both in the display. So I can't click on the tips of both.

That is, I only see the one branch, the other is not visible at all, even though both are marked visible. So I can't see how to diff the two branches in this case. To me this means you can't diff 2 branches in a lot of cases. The sublime merge diff view is so nice, I really wish it had a way to easily diff 2 branches.

@srbs
Copy link

srbs commented Jul 10, 2019

@pwinston, let me explain a bit more the logic behind my comment:

My instructions include hiding every branch (, tag, stash, etc) except the two you want to diff. This was chosen to kind of cheat within the design of the user interface to force one of the two branches (the one with the newest commit) to be at the very top of the commit list/tree. Due to this behavior, you can select the older branch (not the top branch) from the location bar & then scroll to the top of the list via a scrollwheel or dragging the scrollbar & then Ctrl/Cmd + click the second commit (at the top).

It's entirely a cheat around the user interface until a command is created or plugin support is added.

@pwinston
Copy link

pwinston commented Jul 13, 2019

@srbs Wow thanks for your patience in explaining that. It works!

I was correctly showing just the 2 branches. But I was scrolling down and visually looking for the tip of the older one, and it didn't seem to be there. Seemed like history ended before the older branch, although maybe I was just not looking carefully enough. But clicking on the older branch in the Locations pane takes you right there. And then click on the newer one. Great!

@srbs
Copy link

srbs commented Jul 17, 2019

@pwinston, not a problem and glad I could help!

@milesrichardson
Copy link

milesrichardson commented Oct 20, 2019

Here's another trick, using the or operator in the search bar, for when you want to get two far away commits next to each other in the sidebar.

  • Say you have two commits you want to compare:
    • 3c0dada989ddedbc1932b8f3e9313f54612111ef
    • 77b941128cdbb36b749200fd54e2a45cffac4dbb
  • Type ctrl+f (or cmd+f) to search, then type this in the search box
  • commit:3c0dada989ddedbc1932b8f3e9313f54612111ef or commit:77b941128cdbb36b749200fd54e2a45cffac4dbb
  • This will show only those two commits in the sidebar, and you can then ctrl+click (or cmd+click) them to compare the two commits. To see the changeset, you need to change to "contents" view, and you should be able to see a list of all the files on the left, and you can click any one of them to see its changeset.

Here it is on the (massive) v8 codebase. It performs well:

image

@apothecarius
Copy link

I'm currently trying to sum up the changes of my feature branch and cannot use this feature. There are changes that don't show up when I select all the commits that I did. In my branch I have reverted many changes in later commits, but some of these reverts don't show up either

Steps to reproduce:

  • Make a new empty repository
  • Make a commit with a new empty textfile
  • Make a commit with added text
  • Make a commit with that text removed again

I would expect that selecting the two last commits together would show changes, but instead it shows only the removal of that text.

Client Version is 1119 from stable branch

@srbs
Copy link

srbs commented Mar 9, 2020

@apothecarius, that is the correct behavior. Let me take a stab at explaining:

Let's name the commits A, B, & C.

These are the diffs you would see in the UI if you selected a single commit:
A. blank test.txt added
B. 5 lines added to text.txt
C. 5 lines removed from text.txt

However, when you select two commits in Sublime Merge, other git tools, or run git diff <commit 1>..<commit 2> the contents of the two commit are compared.

Commit contents:
A. text.txt, a blank file
B. text.txt, a file with 5 lines
C. text.txt, a blank file

If B & C are selected, the differences between the two commits are just 5 lines removed. If A & B are selected, the differences are just 5 lines added. You'll note that these two selections are identical to the B & C in the diffs above. If you want the changes of two diffs combined, you'll need to compare A & C. in this example.

@apothecarius
Copy link

@srbs thank you for clarifying
So I have to mark the commit from where I made the branch, not my own first commit. That actually works.

@manuelbua
Copy link

Is a git diff command in the works for the command palette? Another interesting idea would be to add two menu items at commit right-click when another commit has the focus, so that one item is for "Diff selected with this" and the other is for "Diff this with selected", to be able to choose the diff direction.

@JosephTLyons
Copy link

+1 for a diff command to show the actual commit differences between two branches.

@abiosoft
Copy link

abiosoft commented Mar 5, 2021

I just purchased a license and was wondering if I made the right decision when I was not able to diff two branches.

The workaround here #255 (comment) works for me but it I would also reiterate that there should be an easier and obvious way of doing this.

Thanks.

@stinos
Copy link

stinos commented Mar 5, 2021

Note that you really don't need all possible steps listed in said comment (e.g. showing only the branches you want to compare is a bit of waste of time and/or definitely not always needed). At least 99% of the time I just click a commit, scroll if needed, Ctrl-click the other commit.

@dpjohnst dpjohnst self-assigned this Mar 10, 2021
@photex
Copy link

photex commented Jun 12, 2021

I would like to put a +1 here for diffing two branches directly without resorting to the workarounds here.

I'm in the middle of some work, and I want to essentially get a PR view between branches. If I hide all branches but those I'm interested in, I get a view that is a reverse of the PR currently.

All in all it's so frustrating to try and get sublime merge to show me what I want, that it was quicker to just open some pointless PRs in our repo manager instead.

@dhempy
Copy link

dhempy commented Jun 24, 2021

This is a major omission. If I can git diff master in a terminal, why doesn't something equally simple work in Sublime Merge? (Build: 2056, Mac). I don't care if it is a menu command, context menu, etc. It should be easily discovered by a new Merge user.

I've tried all manner of Cmd+click combinations between commits and branches as suggested in various threads, without success. For now, I'm sticking with creating disposable PR's in Bitbucket to do what should be a simple local command.

@berezovskyi
Copy link

berezovskyi commented Dec 20, 2021

I actually came to this branch due to the problem described by @photex. It took me a while to realise after seeing a "reverse diff" between feature and main branch tips that I needed to select all commits in the feature branch from the branch point to the feature branch tip to see the "PR" diff.

@thoran
Copy link

thoran commented May 23, 2022

This should have been here from day 1, or close to it. I don't want to have to go to Github to see a complete diff between branches. This request getting on to being about 4 years old now too.

@alxckn
Copy link

alxckn commented May 27, 2022

I am in an organization where it's common to merge back the master branch onto the feature branch. The current diff feature of sublime merge where you have to ctrl+click on two commits to get the aggregated diff is often useless in that case because it will include all changes merged back to the feature branch...

Please add a real diff between branches feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit list An issue related to the commit list enhancement New feature or request
Projects
None yet
Development

No branches or pull requests