如何将现有的 Intellij IDEA 项目从 SVN 切换到 Git SVN
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7069161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to switch existing Intellij IDEA projects from SVN to Git SVN
提问by limc
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.
我目前拥有与 SVN 存储库相关联的现有 Intellij IDEA 项目。我正在考虑将这些项目切换为使用 Git SVN,因为当我没有连接到 SVN 存储库时,我发现需要有一个本地版本控制系统。
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:-
由于 Intellij IDEA 不提供 Git SVN 桥接器,我从命令行运行以下命令将 SVN 存储库克隆到 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.
克隆 SVN 存储库后,我使用 Intellij IDEA 打开基于 Git 的项目。此时,Intellij IDEA 抱怨缺少版本控制目录。我发现 Intellij IDEA 还记得旧的 SVN 配置。由于项目现在包含 .git 目录而不是 .svn 目录,因此 Intellij IDEA 感到困惑,它现在不知道如何连接到任何存储库。
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.
- 在 SVN 存储库中创建一个全新的项目(空项目)。
- 执行“git svn clone”。
- 在其上使用 Intellij 创建项目。
- 此时,Intellij IDEA 检测到 .git 目录并提示我是否将新创建的文件添加到 Git 中。
- 将所有内容从基于 SVN 的项目复制到基于 Git 的项目。
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.
也就是说,我不能在一台机器上的这个 Intellij IDEA 项目上运行 Git,同时在另一台机器上的这个 Intellij IDEA 项目上使用 SVN。两台机器都必须使用 Git,否则 Intellij IDEA 将无法提交到版本控制存储库。我对此很好,我可以在我所有的机器上使用 Git。但是,我试图找到一种方法,而不是为我所有现有的基于 SVN 的项目创建全新的基于 Git 的项目。这很乏味,因为我现在有很多 SVN 项目需要使用 Git 运行。
Is there a better solution for me to switch my SVN projects to Git using Intellij IDEA?
是否有更好的解决方案让我使用 Intellij IDEA 将我的 SVN 项目切换到 Git?
Thanks.
谢谢。
回答by Esko Luontola
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.
您可以从 中选择当前项目的版本控制系统File | Settings | Version Control
。该设置存储在其中一个项目文件 ( .idea/vcs.xml
) 中,因此如果您不将该文件提交给版本控制,则可以在不同的机器上使用不同的版本控制系统。
回答by TMtech
回答by vadishev
BTW, you can use built-in Git support in IntelliJ Idea. Install SubGitinto your Subversion repository and work with created Git repository as usually, i.e. with no git-svn at all.
顺便说一句,您可以在 IntelliJ Idea 中使用内置的 Git 支持。将SubGit安装到您的 Subversion 存储库中,并像往常一样使用创建的 Git 存储库,即根本没有 git-svn。
SubGit works on the server side and synchronizes Subversion and Git repositories on every incoming modification.
SubGit 在服务器端工作,并在每次传入修改时同步 Subversion 和 Git 存储库。
回答by Shadow Man
For file-based projects, you can setup a smudgefilter.
对于基于文件的项目,您可以设置污迹过滤器。
In .git/info/attributes (or .gitattributes) add the line:
在 .git/info/attributes(或 .gitattributes)中添加以下行:
/*.ipr filter=vcs
Then run the following (I store my local scripts in ~/bin, but you can put them wherever):
然后运行以下命令(我将本地脚本存储在 ~/bin 中,但您可以将它们放在任何地方):
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):
我的 filter-vcs-git(涂抹 vcsDirectoryMappingsmapping
行以使用 git):
#!/bin/bash
sed 's/vcs="svn"/vcs="Git"/'
My filter-vcs-svn (clean the vcsDirectoryMappings mapping
lines to use svn):
我的 filter-vcs-svn(清理 vcsDirectoryMappingsmapping
行以使用 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.
这仅适用于带有 sed 的 *NIX 系统。但是您应该也可以通过安装 sed 并编写 .bat 脚本来执行与上述 shell 脚本相同的操作,从而在 Windows 上执行此操作。过滤器只是从标准输入过滤器中获取文件并将过滤后的文件输出到标准输出。
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.
下次检出 .ipr 文件时,它将被过滤以供使用git
,当您添加它 ( git add *.ipr
) 时,它将被清除,以便提交的文件使用.ipr 文件svn
。这似乎适用于所有 git 工具(如git diff
),这些工具被认为该行没有任何变化。