Difference between revisions of "Git-svn"
(category) |
(Contact for svn and git admin rights) |
||
Line 1: | Line 1: | ||
− | [https://git-scm.com/docs/git-svn ''Git-svn''] is an extension of git that allows a git branch to commit to (and get updates from) a svn repository. | + | [https://git-scm.com/docs/git-svn ''Git-svn''] is an extension of git that allows a git branch to commit to (and get updates from) a svn repository. This page explains how to install it and use it in the context of the PCM project. |
− | + | === <u>'''Admin rights'''</u> === | |
+ | |||
+ | Once you have gone through the installation process below, you will be <u>'''required'''</u> to have admin access to both the svn and the git. | ||
+ | For this, please contact either [mailto:ehouarn.millour@lmd.ipsl.fr Ehouarn Millour] or [mailto:laurent.fairhead@lmd.ipsl.fr Laurent Fairhead]. | ||
+ | |||
+ | == Installation == | ||
+ | |||
+ | Git-svn can be installed via the following command on a linux system: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo apt install git-svn | sudo apt install git-svn | ||
Line 8: | Line 15: | ||
To simplify things, a [[Git-svn#install_script|script]] has been created to make the link and ensure the svn is up-to-date/updated when you use [[Git_usage#Simple_commands|''git push'']]. | To simplify things, a [[Git-svn#install_script|script]] has been created to make the link and ensure the svn is up-to-date/updated when you use [[Git_usage#Simple_commands|''git push'']]. | ||
− | |||
The installation script can be found in the repository in the UTIL folder. You can run it with: | The installation script can be found in the repository in the UTIL folder. You can run it with: | ||
Line 23: | Line 29: | ||
This hook is launched each time you run the '''git push''' command. | This hook is launched each time you run the '''git push''' command. | ||
− | It has been modified to run two main commands: a '''git svn rebase''', followed by a '''git svn dcommit''' (see [[ | + | It has been modified to run two main commands: a '''git svn rebase''', followed by a '''git svn dcommit''' (see [[#git_svn_commands|below]]). |
Due to how the pre-push hook is designed, you will need to run the the ''git push'' command twice. | Due to how the pre-push hook is designed, you will need to run the the ''git push'' command twice. |
Revision as of 10:40, 2 October 2024
Git-svn is an extension of git that allows a git branch to commit to (and get updates from) a svn repository. This page explains how to install it and use it in the context of the PCM project.
Admin rights
Once you have gone through the installation process below, you will be required to have admin access to both the svn and the git. For this, please contact either Ehouarn Millour or Laurent Fairhead.
Installation
Git-svn can be installed via the following command on a linux system:
sudo apt install git-svn
To simplify things, a script has been created to make the link and ensure the svn is up-to-date/updated when you use git push.
The installation script can be found in the repository in the UTIL folder. You can run it with:
./UTIL/git_init.sh
The script will:
- Initialize the git-svn branch to follow the svn repository,
- Install the pre-push hook in your .git/hooks folder.
pre-push hook
This hook is launched each time you run the git push command. It has been modified to run two main commands: a git svn rebase, followed by a git svn dcommit (see below).
Due to how the pre-push hook is designed, you will need to run the the git push command twice. The way the script works is summarized in the following diagram.
The reason why two pushes are necessary is detailed below:
The pre-push hook is designed to push the commits as they were before entering the hook. And, since the git svn dcommit command changes the hashes of the commits during the hook, the commits that would be pushed after the hook would be the ones before the git svn dcommit and therefore the git remote master branch would be late compared to the svn repository. The script thus returns with an 'error', telling the user a second push is required. The second push will effectively push the new commits on the git remote master branch. Note that the svn is updated after the first push.
git svn commands
There are two main commands related to this system:
- git svn rebase: This command will get changes from the svn and try to apply your local changes on top of it.
- git svn dcommit: This command will change the hashes of local commits (adding the svn revision to the name of the commit) and commit to the svn. The local commits are not pushed to the git remote repository.