I'm trying to change emails in commits using 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 --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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.