gitgithubbranchcommit

Create commit from several files of another branch


Suppose I have a branch B1 that added files A, B, C, ..., Z.

Suppose I am at branch B2.

What I want is to get a subset of files (say A, E, I, O, U) from the latest state of B1 and create a commit in B2 that adds only them as they are in B1.

How do I do this?


Solution

  • Use git checkout B1 <filename> to retrieve the files. They will automatically be staged for commit, so the next step will be just git commit.