Search code examples
gitsvnversion-controlgit-bashsvn2git

How can I migrate this project from SVN to GIT in this simple situation?


I have the following doubt related how to migrate from SVN to GIT in this specific situation.

Untill now we are using SVN as version control system. Now we have are switching to GIT.

So in this moment I only have to put on GIT a single projet that untill now are handled using SVN. Another important detail is that this project have no an history on SVN because it is a new project and at this time there is only the first commit so luckily I have not to migrate also the history from SVN to GIT.

So basically on my PC I have a Java project that currently is linked to an SVN repository. I have to put on GIT only the current version.

Can I simply go into my local project and do something like this:

cd existing-project-on-my-local-PC
git init
git add --all
git commit -m "Initial Commit"
git remote add origin https://[email protected]/bitbucket/scm/my-project/myproject.git
git push -u origin master

My project also contains the .svn folder containing the old svn informations. How can I exlude it?


Solution

  • You can do it almost like that.

    You should use git add . instead of git add --all, as the former adds everything in and under the current directory, while the latter only updates already tracked files.

    Regarding the .svn directory, either simply delete it, you shouldn't need it anymore and it is probably not the best idea to have a worktree that is controlled by SVN and Git at the same time. Alternatively you can use Gits ignore feature to exclude the .svn folder. If you want to commit this exclusion together with your project, create a file .gitignore with content /.svn/ (this will ignore the folder .svn on the same level as the .gitignore file and everything that is in it), or add the same to .git/info/exclude after doing git init to only ignore it in your local Git repository. Or you can also add it to the ignore file that is on user level to ignore .svn folders in all your local Git repositories, but I think this is not necessary. You can read more about the ignore feature at https://git-scm.com/docs/gitignore.