git + grit 工作目录修订信息
我试图在我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Grit::Repo#head
而不是#heads
– 它会给你对应于.git 的
这是当前签出的提交或引用。Grit::Head
对象/HEAD#heads
将为您提供所有分支。Use
Grit::Repo#head
instead of#heads
– it will give you theGrit::Head
object corresponding to.git/HEAD
which is the currently checked out commit or ref.#heads
will give you all branches instead.