git pre-commit |文件未提交

时间:2018-08-31 10:18:01

标签: node.js git pre-commit

我正在使用this package在预提交挂钩上执行节点脚本。

package.json:

{
  "name": "MyApp",
  "version": "0.0.0",
  "description": "ERROR: No README.md file found!",
  "main": "index.js",
  "scripts": {
    "bump": "node ./bump.js",
  },
  "pre-commit": [
    "bump"
  ],
  "devDependencies": {
    "pre-commit": "^1.2.2"
  }
}

bump.js:

#!/usr/bin/env node
'use strict';

const fs = require( 'fs' )
const fileName = __dirname + '/../src/buildNumber.json'
const file = require( fileName )

const date = new Date()

// set current datetime
file.dateTime = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()

// increment build number
file.buildNumber += 1

fs.writeFile( fileName, JSON.stringify( file, null, 2 ), function ( err ) {
    if ( err ) return console.log( err )
    console.log( JSON.stringify( file ) )
    console.log( 'writing to ' + fileName )
} )

我的问题是未提交对文件的更改。我究竟做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要将更改添加到git暂存区(使用git add),以便它们将成为下一次提交的一部分

"scripts": {
    "bump": "node ./bump.js && git add ../src/buildNumber.json",
 },