-1

At $WORK we use the squash-merge strategy with GitHub, however this makes git blame virtually useless. It only shows the squashed merge commit, which may contain many many changes that do not help.

I cannot change our merge strategy, but I would like to be able to checkout the commits of a merged PR (after it has been squashed onto main) locally. Is there a way to do this?

Simon Walker
  • 5,523
  • 6
  • 30
  • 32

1 Answers1

3

You can use the refs/pull/ namespace of refs that GitHub publishes.

For example:

git fetch origin refs/pull/42/head
git checkout FETCH_HEAD

or fetch into a local branch:

git fetch origin refs/pull/42/head:branch_name
git switch branch_name

This ref is available even after the pull request is merged.

You can also list all of such refs currently fetched into local repository using command git ls-remote:

$ git ls-remote origin 'refs/pull/*/head'
3a12346f1d58b3be4742392d9924043a999428a3        refs/pull/1/head
023496783fab0589e7adf59ada4afc5343d7a252        refs/pull/2/head
ee06715454cacde0c5728be56158dadc30da5cac        refs/pull/3/head

Links

andrybak
  • 2,129
  • 2
  • 20
  • 40