Git: getting info about a change without a local repository?
My program ha开发者_如何转开发s remote access to a git repository over ssh, and sometimes needs to get information (like commit message) about particular git commits. How can I query a remote git repository for this kind of information, without having a local clone of the repository?
I only know of git ls-remote to lookup the available tags and branches and their latest commit id's. You could use that to check if a new commit has been made to a branch.
You could probably do this, by emulating a lot of operation git already does internal and by heavy manual usage of the git plumbing (low-level) commands. However if you do that, you not only need to a lot of really low-level things yourself, you also will end up with very little efficiency in what you do (not only if you request information for a second time).
So I would suggest you to just do a (high-level) clone from the repository and work with it that way, even if that repository will only exist temporary. If you only want to look at the newest commits for example, you can easily restrict what you clone by creating a shallow clone (use the --depth
option with clone).
You could use ssh remote command execution to execute arbitrary git commands
$ssh user@host "cd path/to/repo && git log"
You can also use the repository host's API, if you are hosting with Github, Bitbucket, or similar.
精彩评论