Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move/copy entire file from one branch to another with Git / IntelliJ? [duplicate]

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?

like image 871
Dims Avatar asked Jun 18 '18 18:06

Dims


2 Answers

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'
like image 127
Marina Liu Avatar answered Oct 17 '22 00:10

Marina Liu


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

like image 30
Dmitriy Smirnov Avatar answered Oct 17 '22 00:10

Dmitriy Smirnov