0
  1. I first created a branch, let's call it base.
  2. I pushed that branch to the remote.
  3. I then realized that base was too big, and wanted to extract some stuff into its own branch/PR.
  4. I created small off base.
  5. Pushed small to remote
  6. I then basically removed a whole directory from base.
  7. Pushed the new base
  8. Went to create a new PR from small to base on github

To my surprise, github says there's no difference, that small contains all commits in base. However, if I run (small) git diff base my local git shows the expected difference.

Why does github say otherwise? I then tried to change small with a small nit (just comments), and now github even says it can't merge it and shows a conflict - but only about the nit diff, not the expected whole directory.

A bit mysterious to me...

transient_loop
  • 5,984
  • 15
  • 58
  • 117

1 Answers1

1

When you created small off of base, both of these branches point to the same commit. When you removed the directory on base this was a new commit that exists only on that branch. So base now has this commit and small does not. When Github is generating the diff, it is going to only look at the commits that are on the branch that it will be merging from (in this case small) that don't exist in the branch it is merging into. There aren't any. So the diff is empty.

If you want to create smaller MR's, create a new branch off of what you were going to merge base into and use git checkout base -- <directory> (or small) to get the files from the branch. Commit this and create your PR's with these other branches.

Schleis
  • 41,516
  • 7
  • 68
  • 87
  • Looks like you understood the core here! Thanks first of all. In fact, I think I have had similar issues in the past. So I need to learn to apply the process you are proposing. However, now that I already have `base` - would I first have to delete `base` in order to run `git checkout base -- ` ? – transient_loop Apr 14 '23 at 16:18
  • I just realized another option is to just move the directory to `/tmp`, reset hard `small` to `base`, and then copy the dir back into `base`... – transient_loop Apr 14 '23 at 20:03
  • You need to keep base in order to run `git checkout base`, if the branch doesn't exist, you can't check it out. You need to get commits with your changes into `small` – Schleis Apr 17 '23 at 15:06