I currently have existing Intellij IDEA projects that are tied to the SVN repository. I'm thinking of switching these projects to use Git SVN because I find the need to have a local version control system when I'm not connected to the SVN repository.
Since Intellij IDEA doesn't provide the Git SVN bridge, I run the following command from the command line to clone the SVN repository to Git:-
git svn clone --stdlayout --username myuser http://svnrepo/myproject -A authors.txt myproject
After cloning the SVN repository, I open the Git-based project using Intellij IDEA. At this point, Intellij IDEA complains about missing version control directories. I found out that Intellij IDEA still remembers the old SVN configuration. Since the project now contains .git directories instead of .svn directories, Intellij IDEA gets confused and it doesn't know how to get connected to any repositories right now.
The only workaround that works for me is to do the following:-
- Create a brand new project (empty project) in SVN repository.
- Perform "git svn clone".
- Create the project using Intellij on it.
- At this point, Intellij IDEA detects .git directories and prompts me whether to add newly created files into Git.
- Copy everything from SVN-based project to Git-based project.
That said, I cannot run Git on this Intellij IDEA project on one machine and at the same time use SVN on this Intellij IDEA project on another machine. Both machines must use Git, or else Intellij IDEA will not be able to commit to the version control repository. I'm fine with this and I can use Git in all my machines. However, I'm trying to find a way not to create brand new Git-based projects for all my existing SVN-based projects. This is very tedious because I have quite a few SVN projects that I need to run using Git now.
Is there a better solution for me to switch my SVN projects to Git using Intellij IDEA?
Thanks.
You can select the version control system for the current project from File | Settings | Version Control
. The setting is stored in one of the project files (.idea/vcs.xml
) so if you don't commit that file to version control, you can use different version control system on different machines.
You can use the VCS drop down menu in Version Control Settings dialog
Esko Luontola's answer is outdated. The interface has been changed a bit. I'm not sure since which version. Current is 2022.1. This setting is now under File->Settings->Version Control->Directory Mappings:
BTW, you can use built-in Git support in IntelliJ Idea. Install SubGit into your Subversion repository and work with created Git repository as usually, i.e. with no git-svn at all.
SubGit works on the server side and synchronizes Subversion and Git repositories on every incoming modification.
For file-based projects, you can setup a smudge filter.
In .git/info/attributes (or .gitattributes) add the line:
/*.ipr filter=vcs
Then run the following (I store my local scripts in ~/bin, but you can put them wherever):
git config --global filter.vcs.smudge /path/to/filter-vcs-git
git config --global filter.vcs.clean /path/to/filter-vcs-svn
My filter-vcs-git (smudge the vcsDirectoryMappings mapping
lines to use git):
#!/bin/bash
sed 's/vcs="svn"/vcs="Git"/'
My filter-vcs-svn (clean the vcsDirectoryMappings mapping
lines to use svn):
#!/bin/bash
sed 's/vcs="Git"/vcs="svn"/'
This only works on *NIX systems with sed. But you should be able to do it on windows too by installing sed and writing a .bat script to do the same thing as the shell scripts above. The filters simply take the file from stdin filter it and spit the filtered file to stdout.
The next time you checkout the .ipr file it will be filtered to use git
, and when you add it (git add *.ipr
) it will be cleaned so that the committed file uses svn
. This seems to work cleanly with all the git tools (like git diff
) which are made to think that nothing has changed on that line.
精彩评论