# git-rev-sync

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

Latest version **3.0.2** (published 2022-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-rev-sync
pnpm add git-rev-sync
yarn add git-rev-sync
bun add git-rev-sync
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2022-01-19 |
| First published | 2014-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/git-rev-sync) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 173 |
| Author | kurttheviking |
| Maintainers | kurttheviking |

## Links

- npm: https://www.npmjs.com/package/git-rev-sync
- Repository: https://github.com/kurttheviking/git-rev-sync-js
- Issues: https://github.com/kurttheviking/git-rev-sync-js/issues
- npm.io page: https://npm.io/package/git-rev-sync

## Dependencies (3)

- [shelljs](https://npm.io/package/shelljs.md) 0.8.5
- [graceful-fs](https://npm.io/package/graceful-fs.md) 4.1.15
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) 1.0.5

## Recent versions

- 3.0.2 (latest) — 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
- … 12 more at https://npm.io/package/git-rev-sync/versions

## README

git-rev-sync [![Build Status](https://travis-ci.org/kurttheviking/git-rev-sync-js.svg?branch=master)](https://travis-ci.org/kurttheviking/git-rev-sync-js)
============

Synchronously get the current git commit hash, tag, count, branch or commit message. Forked from [git-rev](https://github.com/tblobaum/git-rev). Supports Node 4+.


## Example

```js
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

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

#### `git.short([filePath], [length])` &rarr; &lt;String&gt;

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])` &rarr; &lt;String&gt;

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])` &rarr; &lt;String&gt;

return the current branch; optional `filePath` parameter can be used to run the command against a repo outside the current working directory

#### `git.count()` &rarr; &lt;Number&gt;

return the count of commits across all branches; this method will fail if the `git` command is not found in `PATH`

#### `git.date()` &rarr; &lt;Date&gt;

returns the date of the current commit; this method will fail if the `git` command is not found in `PATH`

#### `git.hasUnstagedChanges()` &rarr; &lt;Boolean&gt;

returns true if there are unstaged changes; this method will fail if the `git` command is not found in `PATH`

#### `git.isDirty()` &rarr; &lt;Boolean&gt;

returns true if there are uncommitted changes; this method will fail if the `git` command is not found in `PATH`

#### `git.isTagDirty()` &rarr; &lt;Boolean&gt;

returns true if the current tag is dirty; this method will fail if the `git` command is not found in `PATH`

#### `git.message()` &rarr; &lt;String&gt;

return the current commit message; this method will fail if the `git` command is not found in `PATH`

#### `git.remoteUrl()` &rarr; &lt;String&gt;

return the current remote URL; this method will fail if the `git` command is not found in `PATH`

#### `git.tag([markDirty])` &rarr; &lt;String&gt;

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](https://github.com/kurttheviking/git-rev-sync/blob/master/LICENSE)


## Donations

[We're all in this together](https://cash.me/$kurttheviking)

---
_Source: https://npm.io/package/git-rev-sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
