Search code examples
gitgithubcherry-pick

Is it possible to cherry-pick a git commit without changing it?


Situation:

  • I have a repository with commits up to 1234
  • Someone forks it and adds a commit abcd and sends a PR
  • I like to rebase it instead of merge the branch as the branches are not diverged
  • I git cherry-pick the commit, but the new commit is now wxyz as git adds Committer and CommitDate fields and probably some other metadata

My current workaround is to manually git fetch their repo and then git reset --hard onto commit abcd. Afterward I can push my branch to my repo.

It would be especially nice, if I could update the branch from a GitHub PR without resorting to manually fetching and pushing just to add a single commit from a GitHub PR to my repo.


Solution

  • You can add their repo as an origin, fetch all commits, and use git merge --ff-only abcd.