lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

show commits difference between 2 branches (git log branchA...branchB)

Open insane-dreamer opened this issue 1 year ago • 13 comments

This is possible with a custom command of course, but it would be nice to be able to select 2 branches in the Branches panel, press a key and the diff list of commits is shown in the commits panel, which can then be navigated and inspected as usual.

(Maybe this exists but I couldn't find it anywhere.)

insane-dreamer avatar Aug 03 '24 03:08 insane-dreamer

This exists for the most commonly needed special cases, but not for any two branches. For the divergence from a branch's upstream, type u enter; for the divergence from the base branch (usually origin/master), type u b.

Is this what you were looking for, or do you have workflows that require more than this?

stefanhaller avatar Aug 03 '24 08:08 stefanhaller

@stefanhaller Thanks for the info on how to see branch divergence from the upstream branch.

What I am requesting is a different feature, which is to compare the commits of any two branches. This workflow comes up when there is a feature branch or some project-specific branch of a main branch that needs to be compared back to the main branch. (PyCharm allows you to do this for example.)

One suggest for implementation would be to add an option that when a branch is selected pressing a key will compare its log with the checked out branch.

insane-dreamer avatar Aug 08 '24 01:08 insane-dreamer

@stefanhaller when I press u I get a menu to set/unset upstream. Is the branch divergence mapped to another key? Couldn't find it by pressing ? image

insane-dreamer avatar Aug 26 '24 21:08 insane-dreamer

@insane-dreamer what version of lazygit are you using? This one seems pretty old.

mark2185 avatar Aug 27 '24 03:08 mark2185

@mark2185 was using 0.40. Upgraded to latest version and see the new menu/keybinding. Thanks.

insane-dreamer avatar Aug 27 '24 17:08 insane-dreamer

@insane-dreamer Can we close this then, or are there still situations where the current feature set is not sufficient?

stefanhaller avatar Aug 28 '24 18:08 stefanhaller

@stefanhaller so my requested feature is not addressed by the ability to compare a local branch with its upstream (which is useful in itself but a separate use case).

Rather, what I was suggesting was the ability to select a branch in the list of branches and then compare the logs for that branch against the checked out branch. This could be equivalent of running, for example, git log main...workbranch --oneline --source

Or alternatively, one could select any two branches (or tags) in the branch list and press a key to compare those two (regardless of the checked out branch, since git log branchA...branchB does not require either branch to be checked out.

insane-dreamer avatar Aug 28 '24 21:08 insane-dreamer

Yes, I got that.

My question was more if you ever need to do this against a branch other than main. Did you see lazygit's u b command? It does that.

I'd be curious about the use cases where you need to do this for any two branches, not against either main or upstream.

stefanhaller avatar Aug 28 '24 21:08 stefanhaller

Understood. To answer your question, it's not uncommon, in our use case, to need to compare two branches neither of which is origin/master (which is, from what I can tell, the only option using u b). For example, branches that split off from a certain release branch.

insane-dreamer avatar Aug 28 '24 22:08 insane-dreamer

See, that's what I suspected.

In this case you probably want to configure that release branch as one of your main branches, using the git.mainBranches config. You want to do this anyway so that the yellow/green coloring of your commit hashes is correct. And if you do, then u b will work against that release branch (it will pick the closest one of your main branches).

Any others?

stefanhaller avatar Aug 29 '24 06:08 stefanhaller

The other case is when you have to compare branches of code between different platforms. But in theory that could be solved by tagging those branches as mainBranches. So that does work. Being able to select any two branches and compare would be a nice feature for convenience, but your suggested workaround would do the trick in most cases.

insane-dreamer avatar Sep 03 '24 19:09 insane-dreamer

Actually I tried adding branches to mainBranches and that doesn't appear to solve the issue. For one there is no way to select which "mainBranch" you want to diff against. Also mainBranches differ from repo to repo, and it's a bit of a pain to have to update that per repo just to be able to diff two branches. The option to select a branch and diff against the checked out branch would be more user-friendly, imo.

insane-dreamer avatar Sep 04 '24 17:09 insane-dreamer

For one there is no way to select which "mainBranch" you want to diff against.

It always picks the closest one, which is generally what you want when you have, e.g., main, devel, or 2.5-hotfixes.

Also mainBranches differ from repo to repo,

This is not a problem in practice; you can set the config to the union of all the main branches that you have across all your repos, it will ignore the ones that don't exist in a given repo.

Alternatively, we now have per-repo config files (not released yet, though), so this would be a way to configure main branches per repo if you really want to.

But overall, abusing the mainBranches config for cases where you want to diff against something that isn't really a main branch is probably not a good idea.

stefanhaller avatar Sep 05 '24 13:09 stefanhaller