[英]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.