我試圖使用nodegit更改提交中的電子郵件。使用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', '[email protected]', 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)
})
工程沒有錯誤,但沒有施加的變化。我究竟做錯了什麼?
這裏真正的問題是,你不能簡單地修改歷史上更深層的承諾,並希望一切都會通過「自動魔法」重新連接自己。一旦你需要改變這些提交,你實際上需要創建一個新的提交併通過'parent-id'自己連接它們。 – petrpulc