Home > Mobile >  View commit that will be referenced when using tilde ~ or caret ^ with HEAD?
View commit that will be referenced when using tilde ~ or caret ^ with HEAD?

Time:02-18

Since Git operations must be done with precision, and commit histories can sometimes be complex, the use of caret and tilde can sometimes be a little precarious.

Is there a way we can see which commit will be referenced when using tilde or caret before attempting an operation in which they'll be used? Note: I'm aware of dry-run but I prefer something much simpler that just shows the referenced commit, if it exists.

Example

Suppose we have this commit history with parent commits ordered left-to-right:

G   H   I   J
 \ /     \ /
  D   E   F
   \  |  / \
    \ | /   |
     \|/    |
      B     C
       \   /
        \ /
         A

Suppose we want to reference commit F.

We could guess HEAD^2^1 should reference commit F.

Is there a Git command to see the commit/SHA/message for HEAD^2^1 so we can know for sure we're referencing the commit we intend to reference?

Desired output

I would hope to run something like this and receive back a commit that it references:

git <command> HEAD^2^1

commit 64ccfb82af41e92edc4118ed9736a49ffcca7679
Author: John Doe <[email protected]>
Date:   Mon Dec 20 20:52:13 2021  1100

    Update api key usage

CodePudding user response:

git show -s HEAD^2^1

should do the job.

Doc here for the -s option to suppress diff output.

  •  Tags:  
  • git
  • Related