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?

8 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

1
Comment actions Permalink

Any chances this will be also implemented in other products (Webstorm for example)?

0
Comment actions Permalink

Chiriac Oleg VCS functionality is the same across all IDEs, so if something is implemented in IntelliJ then it will be available in other IDEs as well.

0
Comment actions Permalink

Ruslan Kuleshov Thanks for your reply. 
Yeah, digged through Dmitriy's comments here and got a clue where to find this option, however what I was looking for is described in https://youtrack.jetbrains.com/issue/IDEA-156485


0
Comment actions Permalink

Chiriac Oleg it is implemented in the platform, so all IntelliJ-based IDEs, including Webstorm, have it.

The thing is that it is only available when comparing branches with each other. If you call e.g. Compare with a branch action on some file or folder, there is no such action there - https://youtrack.jetbrains.com/issue/IDEA-156485

0

Please sign in to leave a comment.