What is git-rev-sync?
The git-rev-sync npm package provides synchronous access to Git repository information, such as the current branch, commit hash, and other metadata. It is useful for embedding Git information into your application, such as for versioning or debugging purposes.
What are git-rev-sync's main functionalities?
Get the current branch name
This feature allows you to retrieve the name of the current branch in the Git repository.
const git = require('git-rev-sync');
const branch = git.branch();
console.log(branch);
Get the current commit hash
This feature allows you to get the full hash of the current commit.
const git = require('git-rev-sync');
const commit = git.long();
console.log(commit);
Get the short commit hash
This feature provides the short version of the current commit hash.
const git = require('git-rev-sync');
const shortCommit = git.short();
console.log(shortCommit);
Get the commit message
This feature retrieves the commit message of the current commit.
const git = require('git-rev-sync');
const message = git.message();
console.log(message);
Get the commit date
This feature allows you to get the date of the current commit.
const git = require('git-rev-sync');
const date = git.date();
console.log(date);
Other packages similar to git-rev-sync
git-revision-webpack-plugin
The git-revision-webpack-plugin package provides similar functionality but is specifically designed to work with Webpack. It allows you to embed Git revision information into your Webpack build, which can be useful for versioning and cache busting.
git-rev
The git-rev package offers similar functionalities to git-rev-sync but operates asynchronously. It provides methods to get the current branch, commit hash, and other Git metadata, but uses callbacks or promises instead of synchronous calls.
simple-git
The simple-git package is a more comprehensive Git library for Node.js that provides both synchronous and asynchronous methods to interact with a Git repository. It offers a wider range of Git operations compared to git-rev-sync, making it more versatile for complex Git interactions.
git-rev-sync
Synchronously get the current git commit hash, tag, count, branch or commit message. Forked from git-rev.
Example
var git = require('git-rev-sync');
console.log(git.short());
console.log(git.long());
console.log(git.branch());
You can also run these examples via: npm run examples
Install
npm install git-rev-sync --save
API
var git = require('git-rev-sync');
git.short([filePath])
→ <String>
return the result of git rev-parse --short HEAD
; optional filePath
parameter can be used to run the command against a repo outside the current working directory
git.long([filePath])
→ <String>
return the result of git rev-parse HEAD
; optional filePath
parameter can be used to run the command against a repo outside the current working directory
git.branch([filePath])
→ <String>
return the current branch; optional filePath
parameter can be used to run the command against a repo outside the current working directory
git.tag([markDirty])
→ <String>
return the current tag and mark as dirty if markDirty is truthful; this method will fail if the git
command is not found in your PATH
git.message()
→ <String>
return the current commit message; this method will fail if the git
command is not found in your PATH
git.count()
→ <Number>
return the count of commits across all branches; this method will fail if the git
command is not found in your PATH
License
MIT
Donations
We're all in this together