Reader small image

You're reading from  Git Essentials - Second Edition

Product typeBook
Published inNov 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781787120723
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Ferdinando Santacroce
Ferdinando Santacroce
author image
Ferdinando Santacroce

Ferdinando Santacroce is a developer, author, and trainer who loves learning new things. As a software developer, Ferdinando has mainly worked on the .NET platform using C#, bridging the gap between old-style systems and new technologies. Over the span of his career, he has allowed some COBOL applications to talk to remote services, databases, and electronic devices such as cash handlers, scanners, and electronic shelf labels. At the moment, he is committed to helping the largest energy player in Italy to face new challenges in the market by developing Java and JavaScript-based applications. Other than this, he's focusing on continuous improvement and agile movement, which he follows with great care, in conjunction with XP foundations and lean manufacturing. He's one of the organizers of Italian Agile Days, the most famous and appreciated conference in the Italian Agile panorama. Ferdinando loves to share ideas with other professionals and to speak at public conferences; every time he has, he has learned something new. He enjoys writing as well. After a hiatus of a few years, he has started blogging again about his work and passions, which, according to him, are more or less the same thing. Most of what he has learned over the years has been with the help of his friends and colleagues. Other than working within the same team or on the same code base, they have encouraged him to read books and attend inspiring conferences, such as XP Days, Italian Agile Days, and others that have helped his growth.
Read more about Ferdinando Santacroce

Right arrow

Migrating to Git

You often come to Git after using other versioning systems; there are many different VCS in the world but one of the most popular is Subversion, for sure.

Git and Subversion can coexist, as Git has some dedicated commands for exchanging data with Subversion.

The purpose of this chapter is to help developers who actually use Subversion to start using Git instantly, even if the rest of the team will continue to use Subversion.

In addition, the chapter covers definitive migration and preserving the changes' history for people who decide to abandon Subversion in favor of Git.

Before starting

In this first part of the chapter, we will take a look at best practices to maintain safety and work on actual SVN repository with no hassles.

Bear in mind that the purpose of this chapter is only to give readers some hints; dealing with big and complex repositories deserves a more prudent and articulated approach.

Installing a Subversion client

To be able to do these experiments, you need a Subversion tool; on Windows, the most widely used is the well-known TortoiseSVN (http://tortoisesvn.net), which provides command-line tools to both GUI and shell integration.

I recommend a full installation of TortoiseSVN, including command-line tools, as we'll need some of them to make experiments.

...

Working on a Subversion repository using Git

In the first part, we will see the most cautious approach when starting to move away from Subversion, which is to keep the original repository, using Git to fetch and push changes.
For the purpose of learning, we will create a local Subversion repository, using both Subversion and Git to access to its contents.

Creating a local Subversion repository

Without the hassle of remote servers, let's create a local Subversion repository as a container for our experiments:

$ cd C:\Repos
$ svnadmin create MySvnRepo

Nothing more, nothing less; the repository is now ready to be filled with folders and files.

...

Using Git with a Subversion repository

Using Git as a client of Subversion can raise some confusions, due to the flexibility of Git as compared to the more rigid way Subversion organizes files.
To be sure to maintain a Subversion-friendly way of work, I recommend you follow some simple rules.

First of all, ensure that your Git master branch is related to the trunk one in Subversion; as we already said, Subversion users usually organize a repository in this way:

  • A /trunk folder, the main one
  • A /branches root folder, where you put all the branches, each one located in a separated subfolder (for example, /branches/feat-branch)
  • A /tags root folder, where you collect all the tags you made (for example, /tags/v1.0.0)

To adhere to this layout, you can use the --stdlayout option when cloning a Subversion repository:

$ git svn clone <url> --stdlayout 

In this manner, Git will hook...

Migrating a Subversion repository

When possible, it is recommended to completely migrate a Subversion repository to Git; this is quite simple to do and mostly depends on the size of the Subversion repository and the organization.

If the repository follows the standard layout described earlier, a migration takes only a matter of minutes.

Retrieving the list of Subversion users

If your Subversion repository has been used by different people, you are probably interested in preserving commit author's names as is even in the new Git repository.
If the awk command is available (maybe using Git Bash shell or Cygwin while in Windows), there's a script here that fetches all the users from Subversion logs and appends them...

Comparing Git and Subversion commands

In the page that follows, you can find a short and partial recap table, where I try to pair the most common Subversion and Git commands to help Subversion users shift their minds from Subversion to Git quickly.

Remember that Subversion and Git behave differently, so maybe comparing commands is not the best thing to do, but for Git newcomers coming from Subversion, this can help match basic Subversion to the Git counterpart while learning:

Summary

This chapter barely scratches the surface, but I think it can be useful to get a sense of the topic. If you have wide Subversion repositories, you will probably need a better training before beginning to convert them to Git, but for small to medium ones, now you know the fundamentals to start moving away.

The only suggestion I want to share with you is to not be in a hurry; start letting Git cooperate with your Subversion server, reorganize the repository when it is messy, take a lot of backups, and finally, try to convert it; you will probably convert it more than once, as I did, but you will get satisfaction in the end.

In the next chapter, I will share with you some useful resources I found during my career as a Git user.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Git Essentials - Second Edition
Published in: Nov 2017Publisher: PacktISBN-13: 9781787120723
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ferdinando Santacroce

Ferdinando Santacroce is a developer, author, and trainer who loves learning new things. As a software developer, Ferdinando has mainly worked on the .NET platform using C#, bridging the gap between old-style systems and new technologies. Over the span of his career, he has allowed some COBOL applications to talk to remote services, databases, and electronic devices such as cash handlers, scanners, and electronic shelf labels. At the moment, he is committed to helping the largest energy player in Italy to face new challenges in the market by developing Java and JavaScript-based applications. Other than this, he's focusing on continuous improvement and agile movement, which he follows with great care, in conjunction with XP foundations and lean manufacturing. He's one of the organizers of Italian Agile Days, the most famous and appreciated conference in the Italian Agile panorama. Ferdinando loves to share ideas with other professionals and to speak at public conferences; every time he has, he has learned something new. He enjoys writing as well. After a hiatus of a few years, he has started blogging again about his work and passions, which, according to him, are more or less the same thing. Most of what he has learned over the years has been with the help of his friends and colleagues. Other than working within the same team or on the same code base, they have encouraged him to read books and attend inspiring conferences, such as XP Days, Italian Agile Days, and others that have helped his growth.
Read more about Ferdinando Santacroce