10

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?

0

2 Answers 2

10

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' 
Sign up to request clarification or add additional context in comments.

5 Comments

How to select just certain files?
You can use certain filenames or wildcard. Such as copy *.txt from branchA to branchB, you can use git checkout branchA -- *.txt instead.
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 Yes, git checkout command has many functions more than switch to another branch.
4

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

3 Comments

How to do with command line Git?
See Marina's reply
Back to Eclipse then! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.