I squash some commits in Git using git rebase -i origin/master as mentioned in ReinH.com.
After squashing some commits, is there a way to see the original commits? Is it possible to get “diff” of the commits? Can I get the SHA?
If it’s possible, is that still possible after running git gc?
The point of squashing commits is to rewrite history, replacing the original commits with a single commit.
That said, it’s hard to make things actually disappear in git. The easiest way to get at those commits will be via
git reflog. Trygit reflog <branch>for the previous positions of the branch which you rebased.You should be able to find the SHA1 of the tip of the branch just before your interactive rebase. (If the branch no longer exists, try
git reflog showto see the reflog ofHEAD. It should be there too, just more other activity to sort through.)Once you have the SHA1, you’re golden – use
git log -porgitkto view the commits and see their diffs. (If you want to do a lot with it, create a branch there, so you don’t have to paste the SHA1 over and over again.)This will still be possible after running
git gc, as long as it hasn’t been a long time since you squashed those commits.gconly prunes unreachable dangling objects over a certain age.Commits are considered reachable if they’re reachable from anything in the reflogs, and reflogs take 90 days to expire, so you can generally count on those original commits hanging around for three months.