
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
git-rev-sync
Advanced tools
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.
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);
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.
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.
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.
Synchronously get the current git commit hash, tag, count, branch or commit message. Forked from git-rev.
var git = require('git-rev-sync');
console.log(git.short());
// 75bf4ee
console.log(git.long());
// 75bf4eea9aa1a7fd6505d0d0aa43105feafa92ef
console.log(git.branch());
// master
You can also run these examples via: npm run examples
npm install git-rev-sync --save
var git = require('git-rev-sync');
git.short([filePath], [length])
→ <String>return the result of git rev-parse --short HEAD
filePath
parameter can be used to run the command against a repo outside the current working directorylength
parameter can be used to set the desired hash length (defaults to 7
)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.count()
→ <Number>return the count of commits across all branches; this method will fail if the git
command is not found in PATH
git.date()
→ <Date>returns the date of the current commit; this method will fail if the git
command is not found in PATH
git.hasUnstagedChanges()
→ <Boolean>returns true if there are unstaged changes; this method will fail if the git
command is not found in PATH
git.isDrty()
→ <Boolean>returns true if there are uncommitted changes; this method will fail if the git
command is not found in PATH
git.isTagDirty()
→ <Boolean>returns true if the current tag is dirty; this method will fail if the git
command is not found in PATH
git.message()
→ <String>return the current commit message; this method will fail if the git
command is not found in PATH
git.remoteUrl()
→ <String>return the current remote URL; this method will fail if the git
command is not found in PATH
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 PATH
FAQs
Synchronously get the current git commit hash, tag, or branch
The npm package git-rev-sync receives a total of 264,578 weekly downloads. As such, git-rev-sync popularity was classified as popular.
We found that git-rev-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.