Validate if commit exists

后端 未结 6 1053
走了就别回头了
走了就别回头了 2020-12-10 02:45

How to validate whether the commit with given sha exists in current branch?

There are many ways to parse outputs, but I need optimal way which returns boolean (for u

6条回答
  •  难免孤独
    2020-12-10 03:12

    git rev-parse --quiet --verify 
    

    Does not actually verify that commit (I guess SHA1 is what is meant) exists. It verifies that there is an object in the database corresponding to the SHA1 provided. That is, if there is a blob or tree object that matches the SHA1, it will report that it exists, even if it is not a commit.

    git rev-parse --quiet --verify ^{commit}
    

    This will verify that the object exists and that it is an object that can be used as a commit (commit or annotated tag).

提交回复
热议问题