1

enter image description here

I have a git history that looks like this. Is it possible (and how would I) to merge the changes made in commit 5 (in unrelated files than commits 3 and 4) onto commit 2?

1
  • 2
    Create a new branch at Commit 2 and then Cherry-Pick Commit 5 onto that branch
    – CryptoFool
    Commented Oct 4, 2022 at 3:15

1 Answer 1

2

You need to:

  1. Create a branch off of Commit 2
  2. Cherry-pick Commit 5 into that new branch

If the hash for Commit 2 is a84212677 and the hash for Commit 5 is 2677a8421, then you'd do the following:

> git co a84212677
> git co -b newbranch
> git cherry-pick 2677a8421

Your Git repo would then look like this:

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.