git 标签和时间

发布于 2024-11-16 12:28:29 字数 141 浏览 5 评论 0原文

我的印象是,标签的作用就像提交,因为如果我有一个基于旧提交的克隆,我不会期望看到 git 标签输出中列出的新标签。

然而,这种假设显然是错误的。它破坏了我计划使用标签的方式。我正在使用简单的标签。随着时间的推移,其他类型的标签的工作方式是否会有所不同?

I was under the impression that a tag would act like a commit in that if I have a clone based on an old commit, I wouldn't expect to see new tags listed in the git tag output.

However, this assumption is evidently wrong. It kinds wrecks the way I was planning to use tags. I am using simple tags. Would some other type of tag work differently as far as time goes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

郁金香雨 2024-11-23 12:28:29

我不确定你的目标,但是 git 并不能轻松地按指向的提交日期对标签进行排序。

经过一些研究和努力,我想出了这个:

git tag | xargs -I@ git log --format=format:"%ci %h @%n" -1 @ | sort

示例输出:

2008-10-30 08:51:04 -0700 221793e REL_1.0.0
2008-10-31 12:06:57 -0700 51a406c REL_1.0.1
2008-10-31 13:01:18 -0700 e1e9751 REL_1.0.2

经过一些调整,这也可以与“git分支”一起使用来处理指示当前分支的星号。

另一个可能有用的命令......
在日志输出中包含引用名称(分支、标签等):

git log --decorate

您是否有依赖于旧克隆中不存在新标签的假设的工作流程或脚本?
如果您要克隆本地存储库,您可以尝试“git clone --no-hardlinks”。但这可能不是实现您目标的最佳解决方案。

I'm not sure of your goal, but git doesn't make it easy to sort the tags by the date of the commits pointed to.

After some research and effort I came up with this:

git tag | xargs -I@ git log --format=format:"%ci %h @%n" -1 @ | sort

Sample output:

2008-10-30 08:51:04 -0700 221793e REL_1.0.0
2008-10-31 12:06:57 -0700 51a406c REL_1.0.1
2008-10-31 13:01:18 -0700 e1e9751 REL_1.0.2

With a little tweaking, this can also works with "git branch" to handle the asterisk indicating the current branch.

Another command that may be helpful...
Include the ref names (branch, tags, etc) in the log output:

git log --decorate

Do you have a workflow or script that relies on the assumption that newer tags don't exist in old clones?
If you're cloning a local repo, you could try "git clone --no-hardlinks". But it may not be the best solution for your goals.

近箐 2024-11-23 12:28:29

正常情况下的git tag是固定的。如果您昨天引用它并今天引用它,它将指向相同的 SHA/tree/checkout。

但是,随着时间的推移以及您更改存储库(本地或由于 git-fetch 等),相同的 SHA 可能有更多方法来描述 (git describe)相同的提交。多个标签可能指向相同的 SHA(如果没有提交直接指向 SHA,则指向附近的提交),并且 gitdescribe 返回的一个可能会发生变化。

也许你可以描述你正在尝试做的事情,人们可以看看是否有任何想法。

A git tag under normal circumstances is fixed. If you reference it yesterday and reference it today, it will point to the same SHA/tree/checkout.

However, as time progresses and you change your repository (either locally or due to git-fetch et al) the same SHA may have more ways to describe (git describe) that same commit. Multiple tags may point to the same SHA (or nearby commits if no commit points directly to the SHA) and which one git describe returns may change.

Perhaps you can describe what you are trying to do and people can see if there is are any ideas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文