When viewing the diff of my branch vs another, how would I easily import files that my branch is missing?

Imagine you're using the git plugin in intellij Ultimate. Is there a way to import a file that the other branch has but you don't, that is even more conveinient that using the console command:

git checkout origin/some_branch src/com/company/package/MissingFile.java ? What if there are 50 new files that you need from the other branch? Then that command becomes tedious.. I feel like there should be a button for this. I don't want to do a merge. I just want the files from another branch that I don't have. Is there a better way?

4 comments
Comment actions Permalink

Hi John,

you may try selecting a file or a folder in the Project View and invoke Git | Compare with Branch there. Then select the branch – and you'll be presented with the list of changes between current working tree and the selected branch. Then you may show diff for each file and select file chunks you need (or just copy paste the whole content).

Please check if that helps.

0
Comment actions Permalink

Compare with Branch is very handy to pick code snippets from another branch, but it does not work for files that do not exist on the current branch. However, you can use this plugin to checkout files from another branch:

https://plugins.jetbrains.com/plugin/10795-git-checkout-files-from-branch 

0
Comment actions Permalink

1) Save diff between branches to patch:

git diff --no-prefix master..branch-name > branch-name.patch

2) Apply patch in IDEA

0
Comment actions Permalink

Starting from 2018.3, the action to copy files will appear in the Compare branches dialog.

See https://youtrack.jetbrains.com/issue/IDEA-95494#focus=streamItem-27-2968276-0-0

0

Please sign in to leave a comment.