Zulip Chat Archive

Stream: new members

Topic: Comparing branches in GitHub


Stuart Presnell (Jan 04 2022 at 03:48):

Sorry for what seems like a rather elementary GitHub question: when I'm looking at an open PR that depends on another open PR (like #11167 depends on #10850, which in turn depends on #10540), by default the "Files changed" view shows everything that's changed by the whole chain of dependencies (i.e. in this case the cumulative changes introduced in #10540, #10850 and #11167). What's the simplest way to see just what's changed by the PR I'm looking at (i.e. just the changes introduced by #11167, relative to the baseline of #10850)?

Arthur Paulino (Jan 04 2022 at 03:50):

There's this "hidden" feature of GitHub called compare
(just type out "compare" in the end of a repo URL)

Arthur Paulino (Jan 04 2022 at 03:52):

Comparing "branch1branch2" will tell you the file changes that would take place if you were merging branch2 into branch1

Arthur Paulino (Jan 04 2022 at 03:55):

You can also do it in your terminal, but with a significantly less friendly interface. If you're on branch2 and you want to compare it with branch1 (which must be up to date with GitHub), you can do

$ git diff branch1

Stuart Presnell (Jan 04 2022 at 03:57):

Great, thanks!

Eric Rodriguez (Jan 04 2022 at 03:59):

I always wished git diff had the github thing where it said how many commits ahead/behind it was

Stuart Presnell (Jan 04 2022 at 04:02):

In the above case, where I'm comparing branch#SP_factorization_multiplicative (for #11167) against branch#SP_factorization_coprime_pos (for #10850) I get 326 changed files, and I then have to search for the filename of the specific file I've personally changed. Is this exactly what I should expect?

Arthur Paulino (Jan 04 2022 at 04:04):

branch#SP_factorization_multiplicative seems to be more up to date with master. Try merging master into branch#SP_factorization_coprime_pos too. This way you will have a clearer diff

Stuart Presnell (Jan 04 2022 at 04:06):

Ok, thanks

Arthur Paulino (Jan 04 2022 at 04:11):

When comparing "branch1branch2", making branch1 the most updated branch should be enough. That would make branch2 have no other changes w.r.t. branch1 except for the changes you made.

Stuart Presnell (Jan 04 2022 at 04:13):

The other case I'm interested in is slightly more complicated. In branch#SP_algebra_big_operators_prime (#10675) I created a new file algebra/big_operators/prime with some material in it. Then in branch#SP_count_factors_prod (#10855) I added to this file. Then at the suggestion of a reviewer on #10675 I moved the initial material to algebra/big_operators/associated and deleted algebra/big_operators/prime. So when I use the compare page with these two branches it can't find the relevant files to compare (since the changes in branch#SP_count_factors_prod are to a file that no longer exists in branch#SP_algebra_big_operators_prime). Is there any kind of trick I can use here?

Stuart Presnell (Jan 04 2022 at 04:13):

Specifically, I want to find everything that's new in #10855 to make sure I bring it over to algebra/big_operators/associated.

Arthur Paulino (Jan 04 2022 at 04:15):

I would highly recommend a simpler workflow than managing different inter-dependent branches.

One approach that I think works well is stuffing everything in a single branch, and making sure it's always consistent with master. Then open PRs with new branches containing small chunks of your changes form your main development branch

Arthur Paulino (Jan 04 2022 at 04:17):

Otherwise, depending on the complexity of your changes (moving files around, deleting files, renaming files, creating new files etc), it might be way harder than it needs to be

Stuart Presnell (Jan 04 2022 at 04:18):

Thanks, I suspect I've been making life difficult for myself by not using GitHub correctly.

Stuart Presnell (Jan 04 2022 at 04:18):

Of course, I suppose I could just look at the commits in #10855. Clicking on the title of Add lemma finset.count_factors_prod shows what I changed in that one commit. Can I see all the cumulative changes in all commits since that one?

Arthur Paulino (Jan 04 2022 at 04:19):

Yes, in your teriminal you can do git diff <commit hash>

Stuart Presnell (Jan 04 2022 at 04:19):

Ah, thanks!

Arthur Paulino (Jan 04 2022 at 04:22):

Stuart Presnell said:

Thanks, I suspect I've been making life difficult for myself by not using GitHub correctly.

It's also a matter of practice. git is not a very simple tool

Stuart Presnell (Jan 04 2022 at 04:26):

I should sit down and work through a tutorial on git best-practice.

Yakov Pechersky (Jan 04 2022 at 04:47):

You can always merge in another PR's branch into your branch. Or merge in master to reduce the difference to master

Mauricio Collares (Jan 04 2022 at 13:16):

Stuart Presnell said:

Of course, I suppose I could just look at the commits in #10855. Clicking on the title of Add lemma finset.count_factors_prod shows what I changed in that one commit. Can I see all the cumulative changes in all commits since that one?

You can also go to your PR's files tab (https://github.com/leanprover-community/mathlib/pull/10855/files), click on the "Changes from" dropdown on the left, and click on the first and last commits you want to diff while holding Shift.

Mauricio Collares (Jan 04 2022 at 13:24):

Stuart Presnell said:

The other case I'm interested in is slightly more complicated. In branch#SP_algebra_big_operators_prime (#10675) I created a new file algebra/big_operators/prime with some material in it. Then in branch#SP_count_factors_prod (#10855) I added to this file. Then at the suggestion of a reviewer on #10675 I moved the initial material to algebra/big_operators/associated and deleted algebra/big_operators/prime. So when I use the compare page with these two branches it can't find the relevant files to compare (since the changes in branch#SP_count_factors_prod are to a file that no longer exists in branch#SP_algebra_big_operators_prime). Is there any kind of trick I can use here?

Assuming I am not messing up timezones, the problem here is that bors deletes the source branch when it merges a PR, so there is no branch to compare with. You can use the compare page to diff your branch against the commit created by bors: https://github.com/leanprover-community/mathlib/compare/a10cb2f...SP_count_factors_prod

Stuart Presnell (Jan 04 2022 at 13:27):

Thanks!


Last updated: Dec 20 2023 at 11:08 UTC