8

I want to copy not changes, but entire files, which are not present, to on one branch, from another.

It this possible with either Git or IntelliJ?

Currently I am opening diff and copy paste files. But this way I can easily misspell file name and/or file location. Can I add some automation here?

Dims
  • 47,675
  • 117
  • 331
  • 600

2 Answers2

8

Yes, there has an easier way to copy all the files from a branch to another branch by git.

Assume copy all the files from branchA to branchB, then you can execute below commands (also can execute in IntelliJ idea termainal window):

git checkout branchB
git checkout branchA -- .
git commit -m 'copy files from branchA to branchB'
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • How to select just certain files? – Dims Jun 19 '18 at 06:11
  • You can use certain filenames or wildcard. Such as copy `*.txt` from `branchA` to `branchB`, you can use `git checkout branchA -- *.txt` instead. – Marina Liu Jun 19 '18 at 06:15
  • I don't understand, is `checkout` command has additional functionality to copy? `git checkout branchA -- filename` copies filename from `branchA` to current branch without switching to `branchA`? – Dims Jun 19 '18 at 16:14
  • Yes, it does. See https://git-scm.com/docs/git-checkout – Dmitrii Smirnov Jun 19 '18 at 21:58
  • @Dims Yes, git checkout command has many functions more than switch to another branch. – Marina Liu Jun 20 '18 at 01:45
3

UPD. Since IntelliJ 2018.3, there is the Get action available inside the Compare with Working tree dialog.

Old reply: Command-line git can do this, but it is not possible from the Compare branches in IntelliJ. There is a request to add mentioned functionality - please vote for https://youtrack.jetbrains.com/issue/IDEA-95494

As a workaround one could youse the Get action from a file Git history.

There is also a plugin to achieve this https://plugins.jetbrains.com/plugin/10795-git-checkout-files-from-branch

Dmitrii Smirnov
  • 7,073
  • 1
  • 19
  • 29