Reputation: 1260
I have a situation where I committed to a branch B1. In the commit I have several files. Now I want those files to be copied to a Branch B2.
Actually I am using the following command for each file in the commit on my current branch B2:
$ git checkout B1 path/to/file1
$ git checkout B1 path/to/file2
......
$ git checkout B1 path/to/fileN
I guess that there should be a syntax that will allow me to directly checkout the specific commit from branch B1 to branch B2. I tried several solutions but they are rewriting the whole branch which I do not want, nor history of the all files. I only want the state of the file in the particular commit. Overwriting is not a problem.
How to achieve this ?
Upvotes: 0
Views: 89
Reputation: 51850
To get the list of files modified in commit xyz
, run :
# get only the names for the diff between xyz's parent and xyz :
git diff --name-only xyz^ xyz
If you want to checkout these files only :
git checkout B1 -- $(git diff --name-only xyz^ xyz)
# for example : the files modified in the last commit on B2 :
git checkout B1 -- $(git diff --name-only B2^ B2)
Upvotes: 1
Reputation: 16247
git checkout B1 .
You have to specify a path to get what you want, so .
is a path that specifies the current directory.
Upvotes: 1