Abhijith Madhav
Abhijith Madhav

Reputation: 2818

git cherry picking to a different base directory

I have certain commits in a branch, 10.57, which I want to merge to another branch 10.58.

I would normally cherry-pick those commits from 10.57 to 10.58.

There is however a glitch. Certain files have changed their directory structure in 10.58.

Example: The source dir MAAS/ios-web-services in 10.57 has moved to MAAS/apple/ios-web-services in 10.58.

If I cherry pick as before my changes would created afresh as new files/directories in MAAS/ios-web-services instead of getting merged to files in MAAS/apple/ios-web-services.

Is there a way I can ask git to factor in this change in directory structure?

Git cherry pick files, from Directory A to Directory B seems to suggest editing patches and applying them manually. Is there no other easier way?

Upvotes: 8

Views: 6394

Answers (2)

Mohammad Mahmood
Mohammad Mahmood

Reputation: 31

  1. On 10.58, create a directory structure same as 10.57 mkdir -p MAAS/ios-web-services
  2. Move the files from old location to newly created location mv MAAS/apple/ios-web-services/* MAAS/ios-web-services/
  3. Commit these changes git add MAAS/ios-web-services git commit -a
  4. Now cherry pick the change from 10.57 to 10.58
  5. Reverse step 2 i.e move the files from new location to old location
  6. Reverse step1 i.e delete the directory structure
  7. Commit these changes.
  8. Now you have 3 commits, first at step 3, second at step 4, third at step 7. Merge all 3 commits with git rebase -i HEAD~3

Upvotes: 0

nimatt
nimatt

Reputation: 519

If the files only have minor changes you can try using merge.renameLimit as described for merging branches here: How to merge two branches with different directory hierarchies in git?

Upvotes: 1

Related Questions