简体   繁体   English

用红宝石签出git标签?

[英]using ruby to checkout a tag in git?

I want to write a ruby script that is a command line tool that takes a tag ID as a parameter and then runs the equivalent of "git checkout tag_id". 我想编写一个ruby脚本,它是一个命令行工具,将标签ID作为参数,然后运行等效的“ git checkout tag_id”。 I would then use rsync to push the checked out directory to servers. 然后,我将使用rsync将检出的目录推送到服务器。 I've looked at the rugged gem and the git gem, but they seem to interact with git in a way that isn't intuitive in doing something like this. 我看过坚固的宝石和git宝石,但它们似乎以某种不直观的方式与git交互。 Should I just use the system call or is there a more ruby way to do what I'm trying to do? 我应该只使用系统调用还是有其他方法来完成我想做的事情?

I have /User/git_repo cloned from say git@github.com/company/this_repo.git. 我从git@github.com/company/this_repo.git克隆了/ User / git_repo。 Manually I would "git fetch --tags" and then "git checkout tag_id". 手动地,我将“ git fetch --tags”,然后“ git checkout tag_id”。 I would want to then rsync the result over to the servers. 然后,我想将结果重新同步到服务器。

There's the ruby-git gem - install it with $ gem install git . ruby-git gem-用$ gem install git It handles the system command line calls - here's an example for Ruby >= 1.9: 它处理系统命令行调用-这是Ruby> = 1.9的示例:

require 'git'

g = Git.init
       Git.init('project')
       Git.init('/home/schacon/proj',
        { :repository => '/opt/git/proj.git',
           :index => '/tmp/index'} )

g.fetch

g.checkout('tag_id')

You can get an array of tags from g.tags . 您可以从g.tags获取标签数组。 I'd use this over writing my own system calls, as this repo seems to be currently maintained (last commit two days ago ). 我会在编写我自己的系统调用时使用它,因为此回购协议似乎正在维护中( 两天前的最后一次提交)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM