Using git-svn Commands
See the documentation here .
Installing the Package
To be able to use the svn commands in Git install the git-svn package.
Git commands can be used locally to stash use branches and remote git-servers.
Useful Commands
Cloning
Full
Cloning a full repository with branches and tags intact. The login-name can be omitted when those are the same as the current one form the system.
git svn clone \
--revision=20:HEAD \
--trunk=trunk \
--branches=branches \
--tags=tags \
--username=<login-name> \
--authors-file=authors.txt \
"https://svn.scanframe.com/svn/myrepo"
When porting the repository to GitLab the users must correspond.
The authors.txt file example.
admin = Administrator <root@example.com>
myself = My Self <me@example.com>
another = Another Developer <another@example.com>
Shallow
In the example only SVN revision 20 and up is cloned locally by using option --revision=20:HEAD
and surely will speed up cloning on a large repository.
Omitting the option will do a full clone from the start.
Updating from SVN-Server
Fetch
The git svn fetch command updates revisions without affecting the working tree.
Rebase
The git svn rebase command does a fetch and updates the working tree with the latest changes.
When no fetch is wanted, add --local or short -l option.
Rebase & Fetch
In Git this would be the pull and translates to git svn rebase --fetch-all --rebase-merges
or short git svn rebase --all -p. Add option --dry-run or short -n to try it.
Maybe a git stash or creating a local branch git checkout -b my-new-local-branch before
updating from the server could be smart to have a copy to compare with.
Tagging SVN
When adding a tag to an SVN repository it creates a new remote branch for Git locally.
To see the new tag from Git use thegit branch -a command and the following could be the result.
* hotfix
master
remotes/origin/hotfix
remotes/origin/tags/v0.0.0
remotes/origin/tags/v0.0.1
remotes/origin/trunk
Info
Retrieving info about a local branch and remote when a checkout has been performed use the next command. It will only output the URL from all the information.
Conflict Solving
Git dcommit Error
When having a conflict updating the server with changes already committed in the local Git repository.
Command git svn dcommit results in :
Committing to https://svn.scanframe.com/svn/myrepo ...
M trunk/main.cpp
ERROR from SVN:
Item is out of date: File '/trunk/main.cpp' is out of date
W: 0374de056a198fc1783f21a94126b87359b73bc3 and refs/remotes/git-svn differ, using rebase:
:040000 040000 713a7b860c6966456453d36c4091d95691918687 a28843ce399182ed284fc994f449d2d46b0a6517 M trunk
Current branch master is up to date.
ERROR: Not all changes have been committed into SVN, however the committed
ones (if any) seem to be successfully integrated into the working tree.
Please see the above messages for details.
Command git svn info reports the local version is 21.
Path: .
URL: https://svn.example.com/svn/myrepo
Repository Root: https://svn.example.com/svn/myrepo
Repository UUID: f358270c-8f5c-4b07-8fc0-bf386e674591
Revision: 21
Node Kind: directory
Schedule: normal
Last Changed Author: username
Last Changed Rev: 21
Last Changed Date: 2023-03-10 21:43:06 +0100 (vr, 10 mrt 2023)
Command git svn fetch gets the changes from version 22 in a local Git commit.
Command git diff a6d70e4c7cf shows the changes if there are any.
Command git svn rebase merges the Git commit and after this the git svn info command reports version 22.
If the are conflicts these are to be resolved and a new Git commit is pushed using git svn dcommit.