24

I'm not sure how to select a different git repo for each different module I have in my IDEA project, I'm not seeing any option for that, all the git options seem to only relate to one git repo.

Is there a way to differentiate them?, so:

(All inside the same project)

Module A -> repo A
Module B -> repo B

?.

enter image description here

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Artemix
  • 8,497
  • 14
  • 48
  • 75

3 Answers3

37

Go to Settings/Version Control, there you can configure different VCS roots per directory. So in your case define one VCS root per directory containing the module. You should remove the VCS entry <Project> and just add entries for individual modules so that it looks something like this:

VCS config

If you have files modified in several different repositories and hit CTRL+K or otherwise open the commit dialog all changed files will be selected and when you commit your changes a new commit with the same message will be created in all repositories containing the changed files.

If you want to commit files from just a single module either manually select them in the commit dialog or right click your module, go to Git and select Commit Directory.

To push the commits just hit CTRL+SHIFT+K and you should see something like this (notice that both modules are included).

Push dialog

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
  • It's all working now, except the push part. When I select the module and go toVCS->Git->Push it only shows one module, the first one I created when I created the project. The other modules are not in the list, so I can't push the changes. Any idea why this could be happenning?. – Artemix Nov 24 '14 at 19:25
  • Could you please update your question with screenshot of your VCS roots configuration and your project structure? Or some information like that. The push dialog works just fine for me (displays commits to push for both modules). My test project structure is `project/{module1,module2}`. – Bohuslav Burghardt Nov 24 '14 at 19:55
  • I will, give me a sec. – Artemix Nov 24 '14 at 20:05
  • Sorry I can't upload a screenshot of the entire project structure, because of NDA. About the project structure I can tell you that Ihave one project, that contains 2 modules, the first module works alright, and the second added module is the problematic one. The modules don't share folder paths, I mean, they are in different folders without descendants in common. – Artemix Nov 24 '14 at 20:46
  • I understand. Based on your screenshot you might want to try removing the `` VCS root as it might be overriding the VCS roots for individual modules maybe? I added screenshots of my working setup to the answer, hope it will help – Bohuslav Burghardt Nov 24 '14 at 20:54
  • Tried that, didn't help, I still see one module, the same as before. I have the same structure as you now. What version of IDEA are you using?, I have 13.1.4 right now, updating to 14 maybe is a good idea?. – Artemix Nov 24 '14 at 21:38
  • I'm currently on Idea 13.1.5 so that should be about the same. I'll try to play with it a little more and update the answer when I get home. But currently I'm out of ideas as to what could be different in your setup to cause this : (. – Bohuslav Burghardt Nov 24 '14 at 21:45
  • Oh btw, I'm using an Actionscript project, I doubt there would be a difference VCS wise, but who knows. – Artemix Nov 24 '14 at 21:47
  • so if you modified 1 file in each module, then do a commit Dialog.. both files are shown.. does this mean that they each get added to their respective git repositories? 1 file to each repository? – ycomp Feb 27 '16 at 02:00
  • `define one VCS root per directory`. Did that, and now the root is marked as red and it says `Invalid VCS root mapping: The directory /var/www/html/... is registered as a Git root, but no Git repositories were found there.` .. ?! – phil294 Jan 03 '17 at 22:21
  • Any ideas on this. I have managed to add both my modules to CVS Git control but I'm also seeing the Invalid VCS root mapping error. – AndyRED Jul 27 '18 at 11:02
  • lifesaver ..... – DaveH May 30 '22 at 09:24
6

You might have to edit the vcs.xml manually:

  • open the vcs.xml of the top module / project

    ex.: ~/[Top module folder]/.idea/vcs.xml
    
  • Add the vcs entry:

    <mapping directory="$USER_HOME$/sub_module01" vcs="Git" />
    <mapping directory="$USER_HOME$/sub_module02" vcs="Git" />
    
david m lee
  • 2,547
  • 26
  • 14
-1

Okay I think I cracked this one for my circumstance anyway... very confusing as there doesn't seem to be specific instructions on how to set this up anywhere. I have a project that houses an Angular-CLI client-side app and a Grails API server-side app.

So if you are trying to set up CVS using GIT for a multi-moduled project and want to use a separate git repository for each module, not the entire project, then....

  1. Add additional roots by File > Settings > Version Control >
  2. Click the '+' symbol > browse to the project root and select the module folder > OK > VCS: select Git > OK
  3. Repeat step 2 for all other modules
  4. Once all modules are add that you wish to commit to individual repositories > click the settings OK
  5. YES, YES, you will immediately be alerted with a 'VCS root mapping' error!!!
  6. Don't panic. Select the module from the Intellij 'Project/Solution' browser.
  7. Right-click > select Git > Commit Directory > Unversioned Files click the 'browse' link and select the module directory and click the green '+' icon.
  8. You will be warned that that the module is already under Git control but go ahead and add it anyway.
  9. Repeat steps 7-9 for all other modules.
  10. This will remove the 'VCS root mapping' error.
  11. Now go to your version control window which should be located a the bottom of the Intellij application window. There should be an unversioned folder > expand > and you will see all modules listed here.
  12. Add each of the modules by clicking the '+' button... again???!!! :-)
  13. Right-click the default tree and select 'commit and push'.
  14. This will commit all the modules to the local VCS Git
  15. Once the commit has completed a dialogue 'Push Commits' will appear where you will see that each module has an open to add your remote repo url for each module!!!!
  16. Yey!!!!

Hope this is helpful for all :-)

AndyRED
  • 331
  • 1
  • 3
  • 15