2012-09-04 91 views

回答

0

您正在尋找的git寶石

sudo gem install git 

這裏是你如何使用它(自述拍攝):

這是仍在使用
g = Git.init 
    Git.init('project') 
    Git.init('/home/schacon/proj', 
      { :git_dir => '/opt/git/proj.git', 
      :index_file => '/tmp/index'}) 

    g = Git.clone(URI, :name => 'name', :path => '/tmp/checkout') 
    g.config('user.name', 'Scott Chacon') 
    g.config('user.email', '[email protected]email.com')  

    g.add('.') 
    g.add([file1, file2]) 

    g.remove('file.txt') 
    g.remove(['file.txt', 'file2.txt']) 

    g.commit('message') 
    g.commit_all('message') 

    g = Git.clone(repo, 'myrepo') 
    g.chdir do 
    new_file('test-file', 'blahblahblah') 
    g.status.changed.each do |file| 
    puts file.blob(:index).contents 
    end 
    end 

    g.reset # defaults to HEAD 
    g.reset_hard(Git::Commit) 

    g.branch('new_branch') # creates new or fetches existing 
    g.branch('new_branch').checkout 
    g.branch('new_branch').delete 
    g.branch('existing_branch').checkout 

    g.checkout('new_branch') 
    g.checkout(g.branch('new_branch')) 

    g.branch(name).merge(branch2) 
    g.branch(branch2).merge # merges HEAD with branch2 

    g.branch(name).in_branch(message) { # add files } # auto-commits 
    g.merge('new_branch') 
    g.merge('origin/remote_branch') 
    g.merge(g.branch('master')) 
    g.merge([branch1, branch2]) 

    r = g.add_remote(name, uri) # Git::Remote 
    r = g.add_remote(name, Git::Base) # Git::Remote 

    g.remotes # array of Git::Remotes 
    g.remote(name).fetch 
    g.remote(name).remove 
    g.remote(name).merge 
    g.remote(name).merge(branch) 

    g.fetch 
    g.fetch(g.remotes.first) 

    g.pull 
    g.pull(Git::Repo, Git::Branch) # fetch and a merge 

    g.add_tag('tag_name') # returns Git::Tag 

    g.repack 

    g.push 
    g.push(g.remote('name')) 
+0

?最後一次更新是在4年前完成的 –

+0

@TrtTrt你也可以使用[Rugged](https://github.com/libgit2/rugged),它不像git gem那麼簡單,但它更新。檢查自述文件以獲取更多信息。 – alf