Course Tonight

Course Tonight

Did You Know?

You can create any type of product documentation with Docy

Chapter 33: git-svn

Estimated reading: 4 minutes 4 views

Section 33.1: Cloning the SVN repository To create a new local copy of an SVN repository, you can use the following command:

git svn clone SVN_REPO_ROOT_URL [DEST_FOLDER_PATH] -T TRUNK_REPO_PATH -t TAGS_REPO_PATH -b BRANCHES_REPO_PATH

If the SVN repository follows the standard layout with trunk, branches, and tags folders, you can simplify the command:

git svn clone -s SVN_REPO_ROOT_URL [DEST_FOLDER_PATH]

The git svn clone command retrieves each SVN revision and creates a corresponding git commit in your local repository, effectively recreating the history. This process can take some time, especially for repositories with a large number of commits. Once the command is finished, you’ll have a complete git repository with a local branch named master that tracks the trunk branch in the SVN repository.

Section 33.2: Pushing local changes to SVN To push your local git commits to the SVN repository, you can use the following command:

git svn dcommit

Before using git svn dcommit, ensure that your local git history is in sync with the latest changes in the SVN repository. If the command fails, try performing a git svn rebase first.

Section 33.3: Working locally You can use your local git repository as a normal git repository, using familiar git commands:

  • git add FILE and git checkout -- FILE to stage/unstage a file
  • git commit to save your changes locally (these commits won’t be pushed to the SVN repository, similar to a regular git repository)
  • git stash and git stash pop to use stashes
  • git reset HEAD --hard to revert all your local changes
  • git log to access the repository’s history
  • git rebase -i to freely rewrite your local history
  • git branch and git checkout to create local branches

While using git-svn, it’s important to keep the history linear. Subversion is less sophisticated than Git, and performing operations like creating branches, removing/reordering/squashing commits, or moving the history around can be done in a linear manner. Avoid performing merges as merge commits create a non-linear history, which can confuse SVN when pushing to the repository. Instead, use git rebase to reintegrate the history of local branches.

Section 33.4: Getting the latest changes from SVN The equivalent of git pull in git-svn is the command:

git svn rebase

This command retrieves the changes from the SVN repository and applies them on top of your local commits in the current branch. You can also use git svn fetch to retrieve the changes from the SVN repository without applying them to your local branch.

Section 33.5: Handling empty folders Git doesn’t track empty folders since it works with files and their file paths. However, SVN does recognize empty folders. By default, any changes involving empty folders in Git won’t be propagated to SVN when using git-svn.

To address this issue and remove an empty folder in SVN when you locally delete the last file inside it, you can use the following command:

git svn dcommit --rmdir

Note that this command doesn’t remove existing empty folders in SVN; you need to do it manually. To set this behavior as the default or if you’re using a GUI tool, you can use the command:

git config --global svn.rmdir true

This will change your .gitconfig file and add the following lines:

[svn]
rmdir = true

To remove all untracked files and folders that should be kept empty for SVN, you can use the git command:

git clean -fd

Please note: The previous command will remove all untracked files and empty folders, including the ones that should be tracked by SVN. If you need to regenerate the empty folders tracked by SVN, use the command:

git svn mkdirs

In practice, if you want to clean up your workspace from untracked files and folders, you should always use both commands to recreate the empty folders tracked by SVN:

git clean -fd && git svn mkdirs

Leave a Comment

Share this Doc

Chapter 33: git-svn

Or copy link

CONTENTS