git-rev-sync

Synchronously get the current git commit hash, tag, or branch

MIT 27 个版本
安装
npm install git-rev-sync
yarn add git-rev-sync
pnpm add git-rev-sync
bun add git-rev-sync
README

git-rev-sync Build Status

Synchronously get the current git commit hash, tag, count, branch or commit message. Forked from git-rev. Supports Node 4+.

Example

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

Install

npm install git-rev-sync --save

API

var git = require('git-rev-sync');

git.short([filePath], [length]) → <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
  • optional length 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.isDirty() → <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

License

MIT

Donations

We're all in this together

版本列表
3.0.2 2022-01-19
3.0.1 2020-09-02
3.0.0 2020-09-02
2.1.0 2020-09-02
2.0.0 2019-12-15
1.12.0 2018-04-27
1.11.2 2018-04-27
1.11.1 2018-04-02
1.11.0 2018-04-02
1.10.0 2018-02-16
1.9.1 2017-04-25
1.9.0 2017-03-28
1.8.0 2016-10-10
1.7.1 2016-09-21
1.7.0 2016-09-21
1.6.0 2016-04-28
1.5.1 2016-04-17
1.5.0 2016-04-01
1.4.0 2015-09-08
1.3.0 2015-08-07
1.1.0 2015-06-02
1.0.0 2015-01-21
0.1.4 2014-10-07
0.1.3 2014-10-07
0.1.2 2014-10-07
0.1.1 2014-10-07
0.1.0 2014-10-07