What git ls-remote
所做的就是调用另一个 Git(您在上面看到的 URL 中的那个 Git)并询问它的引用:HEAD
、分支名称、标签名称等。但它发送的唯一信息是这些名称和哈希 ID。
As I noted in comments above, each commit—represented by a hash ID, which is sort of the commit's true name—has two timestamps in it.1 To obtain either or both time stamp, you must have the commit. So this means git ls-remote
is not sufficient in general: you might not have the commits whose hash IDs you get from the other Git.
你首先需要运行的是git fetch
,它以相同的方式启动:它调用其他一些 Git 并从中获取它们的分支、标签等的列表,以及每个名称代表的哈希 ID。然后,对于他们的分支,您的 Git 将创建或更新您的远程跟踪名称: their master
成为你的origin/master
, 例如。他们的develop
成为你的origin/develop
。无论他们叫什么名字——refs/heads/*
是完整的形式——你的 Git 创建或更新你自己的相应的refs/remotes/origin/*
姓名。但在你的 Git 能够做到这一点之前,你的 Git 也必须获取提交本身,因此对于他们拥有但你没有的任何提交,你的 Git 需要的,你的 Git 都会获取这些提交。
您可能想要添加--prune
(git fetch -p
简而言之)指示您自己的 Git 删除您现在拥有的不再对应于其 Git 中的分支的任何远程跟踪名称。如果不这样做,您将永远保留过时的远程跟踪名称(或者直到您明确删除它们)。这其实不是harmful如此混乱。
现在您拥有了他们的所有提交,以及您自己尚未发送的提交。你也拥有他们的全部names,更改为您的远程跟踪名称。
You can view these branches with git branch -r
. The default sort order for git branch
is alphabetic-within-group.2 But you can give a --sort=key
option:3
git branch -r --sort=authordate
or:
git branch -r --sort=committerdate
它将根据每个远程跟踪名称指向的提交中存储的相应时间戳进行排序。
Hence:
git fetch -p
git branch -r --sort=committerdate
应该能得到你想要的(除非你想要作者日期;见脚注 1)。
(旁白:我喜欢配置fetch.prune
to true
在我的每用户配置中,以便所有获取行为都像git fetch --prune
总是。)
1The two timestamps are the author timestamp and the committer timestamp. In many cases, both hold the same date-and-time anyway. A new commit in general gets both the same, and then if you copy the commit to a new and improved one, via git commit --amend
or git rebase
or any of the many other ways that can do that, the new and improved commit has the old commit's author information, and you-and-now as the committer information.
2Technically, it's more ASCII-betic, or UTF-8-betic, than alphabetic: a digit comes before uppercase, and uppercase comes before lowercase.
3Your git branch
needs to be new enough to have the --sort
option, which was introduced to git branch
in Git 2.7. If your Git is older, consider using git for-each-ref
.