[英]Amend commits metadata using nodegit
这是我的代码:
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)
})
可以正常运行,但不会应用任何更改。 我究竟做错了什么?
尽可能使用提供的工具。
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
有关完整命令,请参见GitHub帮助 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.