显示远程服务器上提交范围的 git 日志?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5958905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show git logs for range of commits on remote server?
提问by D.C.
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:
我正在寻找一种方法来查询 git 服务器以获取给定提交范围的日志。作为一个 SVN 用户,我的心态是错误的,所以我希望 GIT 专家可以提供帮助。我正在寻找类似的东西:
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 the 20th commit. thanks for any help.
但对于 git 服务器。换句话说,向我展示第 5 次提交到第 20 次提交的日志。谢谢你的帮助。
回答by VonC
First, since there is no simple revision number with Git, you would specify revision as mentioned in the rev-parse command.
首先,由于 Git 没有简单的修订号,因此您可以指定rev-parse 命令中提到的修订版。
But the only command which queries directly a remote repo (without cloning or fetching data) is git ls-remote
, and:
但是直接查询远程存储库(不克隆或获取数据)的唯一命令是git ls-remote
, 和:
- it will display only SHA1, not the log message.
- it works on ref patterns (head, tags, branches, ...), not with revs.
- 它将只显示 SHA1,而不是日志消息。
- 它适用于 ref 模式(头部、标签、分支等),而不适用于转速。
Since log can show diffstats and full diffs, you cannot ask for logs without at least fetching a remote in a local repo.
由于 log 可以显示 diffstats 和 full diffs,因此您不能在不至少在本地存储库中获取远程信息的情况下询问日志。
回答by Bradley Grainger
I think you're trying to transfer some assumptions from Subversion that aren't valid for git. Git is a decentralizedversion control system, so all1 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.
我认为您正试图从 Subversion 转移一些对 git 无效的假设。Git 是一个去中心化的版本控制系统,所以 all1 命令针对您本地的存储库克隆运行,而不是针对远程服务器。此外,在 git 中,没有单一的线性提交历史,因此您需要指定 SHA-1 提交 ID;您不能简单地使用修订号。
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.
如果您尚未克隆远程存储库,则需要运行git clone REMOTE_URL
. 或者,如果您想使用辅助远程服务器,您可以git remote add ALIAS OTHER_REMOTE_URL
在现有存储库中运行。
You'll then need to fetch the commits with git fetch origin
(or git fetch ALIAS
if you've added a secondary remote server).
然后,您需要使用git fetch origin
(或者git fetch ALIAS
如果您添加了辅助远程服务器)来获取提交。
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 documentationor open another question.)
完成后,您可以列出提交(在远程存储库中的分支上)和git log origin/master~5..origin/master
(例如,显示最后五个提交)。或者您可以运行git log master..origin/master
以显示尚未在本地合并的新远程提交。(还有许多其他方法可以指定提交范围;有关更多信息,请参阅文档或打开另一个问题。)
- Some commands, such as
git ls-remote
do run against a remote server, but the majority do not.
- 某些命令,例如
git ls-remote
确实针对远程服务器运行,但大多数命令不会。