• get latest commit hash (support get last commit hash from file)

    • git log --pretty=tformat:%H -n 1 path
    • git log --pretty=tformat:%h -n 1 path
    • git rev-parse HEAD
    • git rev-parse --short HEAD

    Example

    // get last commit of this dir
    latestCommit(null, { cwd: __dirname }).then(console.log);
    // get last commit of single file
    latestCommit(path.join(__dirname, 'path/to/folder/file')).then(console.log);

    Parameters

    • Optional filePath: string

      get latest commit of specific folder, retain null for process.cwd()

    • options: Partial<GetLatestCommitHashOptions> = {}

      spawn options

    Returns Promise<string>