Difference between revisions of "Git-svn"
(Explain a fix if out of sync) |
|||
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. This page explains how to install it and use it in the context of the PCM project. | + | [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 [[Git|PCM project]]. |
=== <u>'''Admin rights'''</u> === | === <u>'''Admin rights'''</u> === | ||
Line 14: | Line 14: | ||
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: |
Latest revision as of 17:36, 13 December 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 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.
Known issues
If you somehow get svn to be desynchronized with the git remote master branch, you can re-synchronize the tags with:
git update-ref refs/remotes/git-svn refs/remotes/origin/master
You may encounter an other issue if git-svn seems to be up-to-date but is not, during the git svn rebase, which might happen due to the local master branch being out of sync with svn. Then synchronize with:
git update-ref refs/remotes/git-svn refs/heads/master