Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy files from a branch to another using git?

Tags:

git

I have a git repository with two branches: master and gh-pages. If I want to copy a file foo from master to gh-pages without merging them. What command should I use? Many thanks.

like image 205
Chongxu Ren Avatar asked Jul 02 '13 02:07

Chongxu Ren


People also ask

How do I copy files from one directory to another in git?

The easiest way to copy files and folders from within a working tree is to use the right-drag menu. When you right-drag a file or folder from one working tree to another, or even within the same folder, a context menu appears when you release the mouse.

Does git branch copy files?

The implementation behind Git branches is much more lightweight than other version control system models. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit.


2 Answers

You can:

git checkout gh-pages
git checkout master foo
git commit -m 'Add file foo to gh-pages.'
like image 75
cforbish Avatar answered Oct 16 '22 19:10

cforbish


If you want to compare all the diffs between 2 branches: you can use git difftool master gh-pages or git difftool <SHA1 of gh-pages> .

If you want to get diff for specific list of files follow this:

git diff master gh-pages -- path/to/file
like image 2
0x90 Avatar answered Oct 16 '22 18:10

0x90