Comprehensive Guide to Git-Rev-Sync
Git-Rev-Sync is an incredibly useful library that allows you to easily retrieve Git repository information from within your Node.js applications. This guide covers a wide range of its APIs, complete with examples to help you integrate it into your projects.
Installation
npm install git-rev-sync
API Examples
1. Get the Current Branch Name
const git = require('git-rev-sync');
const branch = git.branch();
console.log(branch); // e.g., 'main'
2. Get the Latest Commit Hash
const commitHash = git.long();
console.log(commitHash); // e.g., 'abcd1234abcd1234abcd1234abcd1234abcd1234'
3. Get the Commit Message
const commitMessage = git.message();
console.log(commitMessage); // e.g., 'Initial commit'
4. Get the Tag of the Current Commit
const tag = git.tag();
console.log(tag); // e.g., 'v1.0.0'
5. Get the Name of the Last Commit Author
const authorName = git.name();
console.log(authorName); // e.g., 'John Doe'
Application Example
Here is a sample Node.js application that demonstrates the usage of several Git-Rev-Sync APIs:
const git = require('git-rev-sync');
console.log('Branch: ', git.branch());
console.log('Latest Commit Hash: ', git.long());
console.log('Commit Message: ', git.message());
console.log('Tag: ', git.tag());
console.log('Author: ', git.name());
This output will provide a snapshot of the state of your Git repository whenever you run the application.
For more detailed usage and advanced features, make sure to check out the official documentation and explore the library further!
Hash: c246ed3189c75b8a242daba5eb82e6d4a0567fe842ecb09b255e75233ee1c470