1

What I intend to do is similar to what's written here. I did what the top answer says, however, I realised that I had squashed my commits.

This is what my commit history looks like:

Date: <date1>
    commit 3  

Date: <date2>
    commit 2  
    commit 1

(I had squashed commit 1 into commit 2.)

As it says in the top answer to the question linked above, I did git show HEAD~2: file.x but that shows me the file before commit 1, and doing git show HEAD~1: file.x shows me the file after commit 2.

How do I view the file after commit 1 but before commit 2?

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
magikarp
  • 460
  • 1
  • 8
  • 22

1 Answers1

0

If the squash happened recently, you could retrieve the original commits 1 and 2 in the reflog of the relevant branch.

git reflog

which outputs a list of entries of that form :

<commitHash> (optional decoration, as in, branches pointing here) <ref>: <operation>: <details>

There you should find your rebase operation in the recent ones. Create a temporary branch just before this point :

git checkout -b temp HEAD@{n+1}

where n is the corresponding ref you spotted.

Now you can freely inspect your pre-squash commits on this temp branch and dispose of it when you're done.

(Note that all these operations have no impact on your present branches, and you can just dispose of the newly created one when you're done)

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61