How to get SHA of the latest commit from remote git repository?

前端 未结 10 1616
温柔的废话
温柔的废话 2020-12-04 13:58

Does anyone know how to get the latest SHA of a given branch from outside a git repository?

If you are inside a git repository, you can do:

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 14:31

    Using a git URL:

    $ git ls-remote  | head -1 | sed "s/HEAD//"
    

    Using a directory on an accessible system:

    $ git --git-dir=/path/to/repo/.git rev-parse origin/
    

提交回复
热议问题