Merge specific folder from one branch to another

How would you merge a specific branch from one folder to another? For example, I have a production branch and a development branch. Several updates have been done for development in folder-1 and folder-2, but I want to merge into production only updates in folder-1.

What are the proper steps to solve this?

I hardly ever not to say never had this situation.
My guess is i would commit the changes I want to merge from the dev branch and cherry pick it in main.

Now I would rather create a new branch from main and try it out there. You don’t want to ruin your main branch.

If you already committed the folders and the changes are not in separate commits, there are a few options I can thing of.

  • The simplest is git reset --soft to the relevant commit and start over reorganizing your commits accordingly.
  • The other is use git rebase. I saw you can split commits but I am not comfortable with this operation myself.

Could you create and apply a patch?

git diff production development -- folder-1 > changes.patch
git checkout production
git apply changes.patch