git + grit 工作目录修订信息

发布于 2024-09-09 06:24:51 字数 479 浏览 8 评论 0原文

我试图在我的 Rails 应用程序页脚中显示一些 git 版本信息(通过 grit)以进行调试。当我想查看头部时,很简单:

@git_repository = Grit::Repo.new( Ter::Application.root )
head = @git_repository.heads.first
t '.git_info', :revision => head.commit.id, :branch => head.name, :author => head.commit.author.name, :date => l(head.commit.authored_date, :format => :long)

如果我始终使用最新版本(主头部),那么这很有效。但是我找不到一种方法来显示工作目录使用的分支或标签(grit 似乎只在存储库上运行,而不是在工作目录上运行)。

有没有办法在 grit 中显示工作目录信息?

I'm trying to display some git version information (via grit) in my rails application footer for debuging. When I want to see the head, it's straightforward:

@git_repository = Grit::Repo.new( Ter::Application.root )
head = @git_repository.heads.first
t '.git_info', :revision => head.commit.id, :branch => head.name, :author => head.commit.author.name, :date => l(head.commit.authored_date, :format => :long)

which works if I'm always using the newest revision (the main head). However I couldn't find a way to show the branch or tag used by the working directory (grit seems to operate only on the repo, not the working directory).

Is there a way to display the working directory info in grit?

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

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

发布评论

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

评论(1

等风来 2024-09-16 06:24:51

使用 Grit::Repo#head 而不是 #heads – 它会给你对应于 .git 的 Grit::Head 对象/HEAD 这是当前签出的提交或引用。
#heads 将为您提供所有分支。

Use Grit::Repo#head instead of #heads – it will give you the Grit::Head object corresponding to .git/HEAD which is the currently checked out commit or ref.
#heads will give you all branches instead.

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