简体   繁体   English

Amend使用nodegit提交元数据

[英]Amend commits metadata using nodegit

I'm trying to change emails in commits using nodegit . 我正在尝试使用nodegit更改提交中的电子邮件

here is my code: 这是我的代码:

var Git = require('nodegit')

Git.Repository.open('repo')
.then(repository => {
  return repository.getBranchCommit('dev')
})
.then(commit => {
  var eventEmitter = commit.history();
  return new Promise(resolve => {
    eventEmitter.on('end', commits => {
      // Use commits
      commits.forEach(async (commit) => {
        const newSignature = Git.Signature.create('New name', 'new@email.com', commit.time(), commit.timeOffset());
        await commit.amend(
          commit.id(),
          newSignature,
          newSignature,
          commit.messageEncoding(),
          commit.message(),
          commit.getTree(),
        )
        .then(e => {
          console.log('e', e)
          console.log('commit email', commit.committer().email()) // returns old email
        })
        .catch(err => console.log('err', err))
      })
      resolve()
    });

    eventEmitter.on('error', error => {
      // Use error
      console.log('error', error)
    });

    eventEmitter.start()
  })
})
.then(() => {
  console.log('done')
})
.catch(err => {
  console.error('ERROR:', err)
})

Works without errors, but no changes being applied. 可以正常运行,但不会应用任何更改。 What am I doing wrong? 我究竟做错了什么?

Use provided tools if possible. 尽可能使用提供的工具。

git filter-branch command is everything you possibly need. git filter-branch命令是您可能需要的一切。

git filter-branch --env-filter '
export GIT_COMMITTER_NAME="New name"
export GIT_COMMITTER_EMAIL="new@email.com"
export GIT_AUTHOR_NAME="New name"
export GIT_AUTHOR_EMAIL="new@email.com"
' --tag-name-filter cat -- --branches --tags

See GitHub help for full command. 有关完整命令,请参见GitHub帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM