====== Using git with svn ======
Before continuing to read this page, you have two options:
- If you are happy with using svn, stop reading here.
- If you would like to experiment with git, continue reading.
This page has been benefited a lot from the following pages:
* [[http://www.viget.com/extend/effectively-using-git-with-subversion/|Effectively Using Git With Subversion]]
=====Installing git=====
Install first git and a graphical client (e.g. gitk) for it
sudo apt-get install git gitk
=====Applying git clone to the svn repository=====
Create the following ''git-clone-rg-repository.sh'' script in order to clone the repository
#!/bin/bash
USERNAME=
ERROR_CODE=-1
while [ $ERROR_CODE -ne 0 ]; do
# repeat until final success
git svn clone -s https://${USERNAME}@rosegarden.svn.sourceforge.net/svnroot/rosegarden rosegarden.git
# it may be possible that the commands ends to an error like 'RA layer request failed:'
let ERROR_CODE=$?
# just a small pause before repeating the command
sleep 1
done
echo Finished.
The clone the repository (takes a long, long time (several, or, even tens of hours) and 662 Mb to fetch all branches) by running the script
bash ./git-clone-rg-repository.sh
If the script still fails, end the loop by pressing Ctrl+C and rerun the script.
=====Example commit 1: Generating .gitignore and adding it to the subversion repository=====
(These lines have already been executed once.)
==== Generating .gitignore ====
Generate the ignore file with
cd rosegarden.git
git-svn show-ignore > .gitignore
==== Adding file to a following local commit ====
Add the generated file to the local commit
git add .gitignore
and check the status of the repository, if you wish
git status
the following lines will result
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: .gitignore
#
==== Committing locally ====
Commit locally the changes
git commit .gitignore
write then the comment
Add .gitignore file as a result of the following command:
git svn show-ignore > .gitignore
after writing the comment, save the file in editor and finally quit the editor.
This will commit locally the changes and the following information will be given
Created commit 4dcfaa7: Add .gitignore file as a result of the following command:
1 files changed, 181 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
==== Fetching latest changes before commit ====
Before committing, you want make sure that you have the latest version of the source
git svn rebase
Invoking the above command
- reverts temporarily the changes you have made
- downloads all changes from subversion,
- applies the downloaded changes from subversion to the previous version downloaded from subversion, and
- applies again the changes you have made.
The following lines will be printed
First, rewinding head to replay your work on top of it...
Applying: Add .gitignore file as a result of the following command:
==== Committing back to subversion ====
Suggesting that there were no code to merge and no conflicts to solve, you can then commit back to subversion
git svn dcommit
You will see then the following output
Committing to https://hjunes@rosegarden.svn.sourceforge.net/svnroot/rosegarden/trunk ...
A .gitignore
Committed r10792
A .gitignore
r10792 = 8d3f93067b542f7e770c08a3e84c8fb4bb8fb46f (trunk)
No changes between current HEAD and refs/remotes/trunk
Resetting to the latest refs/remotes/trunk
As you can see, the commit has been assigned subversion's version number 10792.
===== A typical short working cycle =====
First you check for new updates
git svn rebase
Then you make your changes, compile and test
[... editing ...]
make
./rosegarden
Now lets prepare for the commit. First lets see what changes we are going to commit
git diff
Add files which were changed and commit them locally
git add [file1 file2 ...]
git commit -m "Message..."
Then one more check for probable new set of changes
git svn rebase
No merge was needed in this example.
Finally, submit the changes
git svn dcommit
That was it. The above set of commands is not optimal, but it works.
===== Using TEMPORARILY a branch =====
First you may want to **fetch** (the code word) the changes in all branches
git svn fetch