Search code examples
gitgit-commitgit-history

Is there a syntax for referring to the commit which followed a commit in branch history?


If I have a specific hash, call it A, I can get to the parent by A^. But is there a way to get to the commit that followed A in the branch history? Something like A+1, such that A is (A+1)^? I want to check out the commit after the one I have the hash for, and then the one after that, and so on, to inspect them. But they're really buried. Any easy way to check them out given a reference hash other than searching git log output?


Solution

  • I want to check out the commit after the one I have the hash for, and then the one after that, and so on, to inspect them

    git rev-list --first-parent --reverse $thathash..mybranch
    

    will list you all the commits you want to check out, in order. If you don't just want the linear history but all commits descended from that hash in the branch tip history replace --first-parent with --ancestry-path and you can use the sequencing options to decide what order to visit them in.