seebinetpqls
seebinetpqls

Reputation: 1

Pulling Just One Folder from One Branch to A Different Branch Git

I have two branches A and B, B was branched off from A

there were different changes made on both A and B since then

I would like to know the git commands to move just one folder from A to B without pulling any other changes

Upvotes: 0

Views: 182

Answers (1)

krisz
krisz

Reputation: 2696

How do I merge changes to a single file, rather than merging commits? is basically the same question, but many of the answers are wrong.

I fixed/improved some of the better solutions.

  • To merge the changes and get the commits too (this will cause duplicate commits if you later merge A and B, could be avoided with rebase):
    git checkout B
    git format-patch --stdout ..A -- <path> | git am -3
    
  • To merge the changes without the commits, use this answer (be aware A and B is swapped) or this simpler solution:
    git checkout B
    git diff ...A -- <path> | git apply
    # stage changes and commit
    
  • To overwrite B with the version of the files in A:
    git checkout B
    git checkout A -- <path>
    # commit
    

Upvotes: 1

Related Questions