GIT get the commit hash prior to a specific commit

GitShellCentos

Git Problem Overview


git 1.7.1

git show <hash>:<file> gives me the file based on the commit hash provided

I am trying to figure out how to bet the file of the previous commit before the one who's hash I have.

I know I can always use the log to get all hashes and figure out the one i need but that's not a good solution in my case as I am trying to minimise the number of commands I need to do for performance issues.

Was wondering if there is a simple way.

Git Solutions


Solution 1 - Git

Use git show HEAD^1. You can replace HEAD with your commit-hash

Edit to take multiple parents into account:

In case you want to see all the parents for a commit hash, you can use git rev-list --parents -n 1 <commithash> or use git show as @Bhaskar suggested in the comments to the question.

There are other ways as well as explained here.

Solution 2 - Git

Depends on commit message: git log | grep -A <number_of_lines> <commit_hash> <number_of_lines>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontransilvladView Question on Stackoverflow
Solution 1 - GitNikhil GuptaView Answer on Stackoverflow
Solution 2 - GitAnton MelnykView Answer on Stackoverflow