Gracjan Polak
Gracjan Polak

Reputation: 596

Repeatable git cherry-pick

git cherry-pick is not idempotent in the sense that commit hash after cherry-picking depends on current time and current user (as commiter).

I'd like to have the idempotence propery, that means twice the sequence:

git reset --hard BASE-COMMIT
git cherry-pick INTERESTING-COMMIT

and then again:

git reset --hard BASE-COMMIT
git cherry-pick INTERESTING-COMMIT

results in exactly same commit hash at HEAD both times.

Is there a way to tell git to reuse Committer Name and Committer Date from the original commit?

Upvotes: 1

Views: 196

Answers (1)

Edward Thomson
Edward Thomson

Reputation: 78673

You can modify the commit date when you check in the cherry-pick. For example:

git reset --hard BASE-COMMIT
export GIT_COMMITTER_DATE=$(git log -1 --format='%ct' INTERESTING-COMMIT)
git cherry-pick INTERESTING-COMMIT

This assumes that the user is stable also, otherwise you will also need to set GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL, like this:

export GIT_COMMITTER_NAME=$(git log -1 --format='%cn' INTERESTING-COMMIT)
export GIT_COMMITTER_EMAIL=$(git log -1 --format='%ce' INTERESTING-COMMIT)

Upvotes: 3

Related Questions