1

I have a commit, which was merged in such a way that git log is a mess. I want to know which commit is a parent to a given commit, i.e., what was the working area state before that commit was merged.

I've tried to use commit_id~1 as 'previous', but I failed. How can I get 'previous commit' in git?

George Shuklin
  • 6,952
  • 10
  • 39
  • 80
  • 1
    Please explain in more detail what "but I failed" means. Show the exact output from the session. – Code-Apprentice Oct 26 '17 at 12:48
  • It's easy to do with VS2017, or SourceTree, or bithucket, do you *have* to use the command line? – Neil Oct 26 '17 at 12:49
  • See https://stackoverflow.com/questions/2221658/whats-the-difference-between-head-and-head-in-git for tips on referring to ancestors of a given commit. – Code-Apprentice Oct 26 '17 at 12:51

1 Answers1

2

If you want the hashes, two equivalent choices:

 git log --pretty=%P -n 1 <commit>
 git show --pretty=%P <commit>
Ivan Sheihets
  • 802
  • 8
  • 17