how to convert svn repository to git on Windows - windows

We have remote svn repository and we want it to convert to git.
Could you please tell me how is it possible to do it on Windows?
Thank.

Install application on Windows:
Git for Windows.
TortoiseGit
Find out the svn repository URL and copy it
Something like this:
Invoke TortoiseGit Clone dialog
Right click on destination folder, e.g. D:\SVN\ToGit, and Click Git Clone...
Check the From SVN repository checkbox
If you copied the URL first, then invoke the clone dialog, TortoiseGit will get the copied URL from clipboard and paste it into the URL text field for you. So, you don't paste it by yourself. Just have look at it to see if it's correct.
And if you right click on destination folder, TortoiseGit also fill the Directory text field for you. Also, take a look to see if it's what you want.
So, just check the From SVN repository checkbox.
And if the svn repository has the standard layout, say trunk, tags, branches, you don't need to do anything further.
Click the OK button to go
Then, starting to clone a svn repository to git repository.
Something like this:
As you can see, TortoiseGit just properly uses Git for Windows command git svn clone to clone it.
git.exe svn clone "svn://svn.code.sf.net/p/tortoisesvn/code/" "D:\SVN\ToGit\tsvn" -T trunk -b branches -t
So, basically, you can go Git Bash/CMD and re-use that command line, and also get the same result.
NOTE: If you can see the r1, r2, r3..., you can stop the cloning anytime, and resume it later by using the same command line.
Clone a local svn repository
With TortoiseGit 2.4.4+
Just copy the svn local path into URL of Clone dialog. See:
Again, Check the From SVN repository checkbox
Cloning:
TortoiseGit 2.4.4+ will use file:/// protocol to clone a local svn repository.
After you get a git repository, you can commit there. And push the commit back to origin svn repository by using TortoiseGit ->SVN DCommit..., something like svn commit.
As you can see, the command is git svn dcommit.
And if the origin svn repository has some new commit(s) need to update, you can use TortoiseGit ->SVN Rebase to fetch the svn commit and then merge/rebase on the latest commit. Something like svn update.
It uses git svn fetch then uses git rebase to merge/rebase the fetched changes.
For command line, you could just use git svn rebase.
Read Pro Git v2 - Chapter 9 for more information and examples.

You can use git-svn which is a tool that lets you convert svn repositories to git repositories. See the git documentation for more information.

Context:
Remote svn server with HUGE repository of several projects. However I only wanted to migrate one project from SVN to Git
Here's how I did it:
Requirements:
Git Extensions - Git Extensions
Visual SVN Server (also get eval license) - Visual SVN Server
Chocolatey windows package manager - Chocolatey
Git version 2.6.2 (use chocolatey in cmd: choco install git --version 2.6.2 )
What to do:
1. Get users who committed into authors file
Open cmd to root of local svn project copy and run:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
Put the resulting authors file somewhere you can find it
Open and Edit the authors-transform.txt file by adding the name and the email into the <> line by line for each committer
2. Copy your SVN repository from the server to a local on your working drive (example: c:/repo/Repository
3. Install Visual SVN and point the storage of the server to the /repo folder
Also find an open port for it to run on
Set permissions on the authentication to windows for the server
You may have to create a user for the server as well
Also set permissions for the specific project within the server to your user
4. In the destination folder for your new cloned SVN repo hold shift and click Git Browse to open Git Extensions, go to Start, and click Clone SVN
Point to the local svn server you created for the destination (example http://localhost/svn/repo/Repository/Development/ProjectName)
I unchecked the trunk, tags, and branches but YMMV
Point the authors file to wherever it is saved
Click clone
Reasons:
Git 2.6.2 because it was the latest version that didn't cause an address issue
Git Extensions because it minimized all the command line work for the cloning
Visual SVN because I was having permissions issues on the server and the "git svn" commands responded better to an http://localhost..... address than the file:// that was suggested in the many places I researched
Chocolatey because I didn't see any other way to get that version of Git

I ended up doing this so much, I made a batch script to help out:
usage: SvnToGit <path/to/svn-repo> <local-checkout-dir> <remote-git-url>
Prerequisites
You should already have the URL to the empty git remote repository.
You should have a pre-existing authors.txt file at the root ready to
go.
Unless Git understands your svn format, you will need to run
svnserve to 'serve' the repo. You can create a window service to do,
something like this:
c:>sc create svnserve binpath="\"svnserve.exe\" --service -r C:\Users\UserName\Repositories\Svn" displayname="Subversion Server" depend=Tcpip start=auto
Caveats:
Check the intermediate results, occasionally something may fail
(especially svn clone).
Note the section for manual changes if needed
for tags. Perhaps, this could be done in batch file, but it seemed
complex and not a high priority for me. There is a PAUSE here, so
you can make these changes manually.
I have not tested this on many systems, you might need to tweak
the script a bit to adjust to your system.
The actual batch file:
REM Argument 1: Path to your repository
REM Argument 2: Path to your new Git working directory
REM Create authors.txt file
REM It will contain lines like:
REM SomeCoder = Some Guy <some.guy#example.com>
REM If Git is now aware of the format of svn repository, you will need to use svnserve:
REM svnserve -d -R --root path/to/your/repository
PAUSE
IF EXIST bare.git\NUL RD /S /Q bare.git
IF EXIST GitTemp\NUL RD /S /Q GitTemp
REM The following will not work, if SVN is using a newer FS than what Git is aware of
REM git svn clone file:///%1 --prefix=svn/ --no-metadata -A authors.txt --stdlayout GitTemp
REM So, use
git svn clone svn://localhost/%1 --prefix=svn/ --no-metadata -A authors.txt --stdlayout GitTemp
PAUSE
REM GitIgnore
cd GitTemp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m "Convert svn:ignore properties to .gitignore."
cd ..
REM Bare Repo
git init --bare bare.git
cd bare.git
git symbolic-ref HEAD refs/heads/trunk
cd ..
cd GitTemp
git remote add bare ../bare.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare master
cd ..
REM clean up SVN type stuff
cd bare.git
REM git branch -m trunk master
git branch -m svn/trunk master
git symbolic-ref HEAD refs/heads/master
cd ..
REM Manual changes if needed for tags
REM git for-each-ref --format='%(refname)' refs/heads/tags |
REM cut -d / -f 4 |
REM while read ref
REM do
REM git tag "$ref" "refs/heads/tags/$ref";
REM git branch -D "tags/$ref";
REM done
PAUSE
REM Working Directory
git clone bare.git %2
cd %2
git checkout master
git remote remove origin
PAUSE
git remote add origin %3
REM Then
git push -u origin master

Related

git/visual studio

How do I create a new GitHub repository from a local branch from a cloned repo with visual studio?
Been searching and trying for 3 days but nothing works plz help
you can reveal the files in file explorer from that repository and after that takes the file without git and implement a new git repository
In terminal
$ cd PARENT-FOLDER
$ git init REPOSITORY-NAME
Initialized empty Git repository in /Users/local/repo/.git/
Creates a new folder on your computer, initialized as a Git repository
$ cd REPOSITORY-NAME
Changes the working directory
$ mkdir docs
Creates a new folder called docs
$ cd docs
$ git checkout --orphan newbranch
Creates a new branch, with no history or contents, called newbranch , and switches to the newbranch branch
$ git rm -rf .
Removes the contents from your default branch from the working directory
git add .
git commit -m ‘’
$ git remote add origin https://github.com/USERNAME/REPOSITORY.git
$ git push -u origin BRANCH
commits & pushes changes to repo

git commands working on windows command line but not in Git Bash terminal

I'm working on remote repository with git commands on windows cmd and it works well, but when working with git commands in git bash terminal I get error:
Your configuration specifies to merge with the ref 'refs/heads/feature/branch-name'
from the remote, but no such ref was fetched.
How can I fix it for git bash terminal?
Check first, in your git bash session, the ouput of:
git branch -avv
git status
Make sure the name of the branch you are in matches the remote one, especially considering the case (uper/lowercase), in case it is insensitive in a CMD session, and sensitive in a bash session.
See this example.
If the list of branches show the local one is not linked to a remote tracking one, then, as I documented in "[Difference between git checkout --track origin/branch and git checkout -b branch origin/branch][2]":
git branch -u origin/branch branch
It started working when I moved to the main branch (next).
But, when i switch back to my branch this is what I get:
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> feature/branch-name
Finally found the answer here:
Why do I have to "git push --set-upstream origin <branch>"?
git push -u origin <your-local-branch-name>
So if your local branch name is coffee
git push -u origin coffee

Can't commit update-index on Windows

I have a executable file called post_deploy that's run on my OpenShift gear after a push, but it wasn't executable so I ran:
git update-index --chmod=+x .openshift/action_hooks/post_deploy
But every time I did a git add to commit the file, the file would loose the executable permission. If I tried to do a commit, git would tell me there was nothing to commit. I eventually had to pop over to Cygwin to get it to work, but how can I get this to work in Window's Command Prompt?
Check your Git version: with Git 2.9.1, you can add with chmod
git add --chmod=+x -- yourFile
Also check the value of git config core.filemode. I suspect it should be false (which is expected in an environment which does not support executable bit).
Still, the add --chmod=+x should be enough to record that executable bit in the Git repo.
Finally, clone your repo in a Linux/Cygwin environment and check if the file is not already executable there.
The OP NicholasJohn16 reports below using "How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?" to solve the issue.

`git add` doesn't add files to track on Windows

I have a local folder which I wanted to convert to a Git repository and then push to a remote repository. I ran the command git init in the project folder and then used the command git add .. When I run the command git status, I get the message that I have untracked files. I ran the git add . command multiple times but I see the same message.
What should I do to track these files so I can push to a remote repo?
I'm using Windows 8.1 x64 machine.
UPDATE: Please see the answer below.
I used the command git config --system core.longpaths true to fix the error for longer file names. I was able to add all files after making that change.

git windows post pull

I have recently converted from svn.
My server is under Windows (don't blame me, it wasn't my choice :}
I have created a repo with two branches "master" and "stable".
On my server I want to get files from stable branch.
I have done:
git clone git://url/.git src
cd src
git checkout --track -b stable origin/stable
Previously I had a .bat script
cd my_repo_dir
svn update
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
and it worked, now with git
cd my_repo_dir
git pull
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
nothing is executing after git pull, whether it is successful, or up-to-date.
It just exits to prompt with no warning.
I thought about hooks.
I have created:
.git/hooks/post-receive
.git/hooks/post-update
both files with the same contents:
echo APPLICATION_STAGE = 'production' > conf\__init__.py
net stop apache2.2
net start apache2.2
and nope, it is not executing either...
Maybe I am missing interpreted declaration line (#!/bin/sh on *nix)
but I am not sure what it is on windows...
Few points:
Make sure you have git.exe on path. Do a where git and you must get something like
C:\Program Files (x86)\Git\bin\git.exe
If git.cmd is being used ( from C:\Program Files (x86)\Git\cmd\git.cmd ), you have to do call git pull for it to continue execution. I would say add git.exe to path and start using it.
Even on Windows, you must have the shebang - #!/bin/sh for the hooks to properly run.
If you want a hook to run on pull, you probably want to use the post-merge hook. post-receive and post-update run on remote repos when you push to them.
git is probably a batch wrapper around the real executable. Use call git pull.
And those hooks only fire when content is pushed from a remote location, as far as I can tell from the documentation. So they're ignored for pull.

Resources