I am looking for a way to query a git server for its logs for a given range of commits. Being an SVN user, I'm in the wrong mindset so Im hoping GIT experts can help. I'm looking to something similar to:
svn log -r 5:20 --xml svn.myserver.com
but for a git server. In other words, show me the logs for the 5th commit through to开发者_JAVA百科 the 20th commit. thanks for any help.
First, since there is no simple revision number with Git, you would specify revision as mentioned in the rev-parse command.
But the only command which queries directly a remote repo (without cloning or fetching data) is git ls-remote
, and:
- it will display only SHA1, not the log message.
- it works on ref patterns (head, tags, branches, ...), not with revs.
Since log can show diffstats and full diffs, you cannot ask for logs without at least fetching a remote in a local repo.
I think you're trying to transfer some assumptions from Subversion that aren't valid for git. Git is a decentralized version control system, so all¹ commands run against your local clone of the repository, not against a remote server. Also, in git, there isn't one single linear history of commits, so you need to specify SHA-1 commit IDs; you can't simply use revision numbers.
To get a log, you must first transfer the commits to your local clone of the repository, and then you can query them.
If you haven't already cloned the remote repository, you will need to run git clone REMOTE_URL
. Alternatively, if you're wanting to use a secondary remote server, you can run git remote add ALIAS OTHER_REMOTE_URL
in an existing repository.
You'll then need to fetch the commits with git fetch origin
(or git fetch ALIAS
if you've added a secondary remote server).
Once you've done that, you can list commits (on branches in the remote repository) with git log origin/master~5..origin/master
(to show the last five commits, for example). Or you could run git log master..origin/master
to show the new remote commits that haven't been merged locally yet. (There are many other ways to specify commit ranges; for more information see the documentation or open another question.)
- Some commands, such as
git ls-remote
do run against a remote server, but the majority do not.
精彩评论