not-an-aardvark/git-delete-squashed

Doesn't work when a branch contains commits that have been applied in more than one merge

ggilder opened this issue · 2 comments

For example:

  1. I make a branch "develop-B" which is branched off "develop-A"
  2. "develop-A" is squash-merged into main branch
  3. "develop-B" is squash-merged into main branch

Now the approach this script uses (git cherry) fails because there is not a single commit that matches the squashed commit representing "develop-B", it's spread across two commits.

I think that it's possible to fix this and simplify the script by using git merge-tree and git merge-base. Here's an example: https://github.com/ggilder/dotfiles/blob/master/bin/git-delete-merged-branches#L9

@ggilder The approach you're taking in the script you link to won't work in general because it gets broken by subsequent work in the repo.

  • make a branch work that modifies file A
  • squash merge it to master, but don't delete it
  • later merge a different branch to master that deletes file A

Merging work to master at this point will produce a change. Your script would not consider work eligible for deletion, but the one in this repo should.

@n8gray that's a good point, I hadn't considered that scenario. I suppose I might have to run both scripts to cover all the possibilities.