You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Grit gives you object oriented read/write access to Git repositories via Ruby.
The main goals are stability and performance. To this end, some of the
interactions with Git repositories are done by shelling out to the system's
git command, and other interactions are done with pure Ruby
reimplementations of core Git functionality. This choice, however, is
transparent to end users, and you need not know which method is being used.
This software was developed to power GitHub, and should be considered
production ready. An extensive test suite is provided to verify its
correctness.
Grit is maintained by Tom Preston-Werner, Scott Chacon, Chris Wanstrath, and
PJ Hyett.
Grit's Git repo is available on GitHub, which can be browsed at:
http://github.com/mojombo/grit
and cloned with:
git clone git://github.com/mojombo/grit.git
Development
You will need these gems to get tests to pass:
mocha
Contributing
If you'd like to hack on Grit, follow these instructions. To get all of the dependencies, install the gem first.
Fork the project to your own account
Clone down your fork
Create a thoughtfully named topic branch to contain your change
Hack away
Add tests and make sure everything still passes by running rake
If you are adding new functionality, document it in README.md
Do not change the version number, I will do that on my end
If necessary, rebase your commits into logical chunks, without errors
Push the branch up to GitHub
Send a pull request for your branch
Usage
Grit gives you object model access to your Git repositories. Once you have
created a Repo object, you can traverse it to find parent commits,
trees, blobs, etc.
Initialize a Repo object
The first step is to create a Grit::Repo object to represent your repo. In
this documentation I include the Grit module to reduce typing.
In the above example, the directory /Users/tom/dev/grit is my working
directory and contains the .git directory. You can also initialize Grit with
a bare repo.
repo = Repo.new("/var/git/grit.git")
Getting a list of commits
From the Repo object, you can get a list of commits as an array of Commit
objects.
Called without arguments, Repo#commits returns a list of up to ten commits
reachable by the master branch (starting at the latest commit). You can
ask for commits beginning at a different branch, commit, tag, etc.
This tree contains two Blob objects and two Tree objects. The trees are
subdirectories and the blobs are files. Trees below the root have additional
attributes.