LoginSignup
6
3

More than 5 years have passed since last update.

gitでコミットしたファイルの一覧を取得

Posted at
$ git log -1 --name-only

NodeJSで最新のコミットログから、コミットしたファイルの一覧を取得する

CoffeeScript
exec = require 'exec'

exec 'git log -1 --name-only', (obj, log)->
  lines = log.split('\n')
  commit = lines.shift().replace(/^commit /, '')
  author = lines.shift().replace(/^Author:\s+/, '')
  date = lines.shift().replace(/^Date:\s+/, '')
  lines.shift()

  files = []
  while true
    file = lines.pop()
    if file
      files.unshift(file)
    else 
      break

  comment = lines.join('\n')
  comment = comment.replace(/^\s{4}/g, '')

  item =
    commit: commit
    author: author
    date: new Date(date)
    files: files
    comment: comment

  console.log JSON.stringify(item, null, '  ')
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3