Difference between revisions of "Git-svn"

From Planets
Jump to: navigation, search
(Explanations of the git-svn system, the pre-push hook, etc)
 
(category)
Line 39: Line 39:
 
* '''git svn rebase''': This command will get changes from the svn and try to apply your local changes on top of it.
 
* '''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.
 
* '''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.
 +
 +
[[Category:FAQ]]

Revision as of 14:23, 18 September 2024

Git-svn is an extension of git that allows a git branch to commit to (and get updates from) a svn repository.

It 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.

Install script

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. Pre-push.png

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.