About git and SVN collaboration


Write in front:

  • This article is based on git command to expand the introduction, window graphical operation of tortoiseGit, can also be completed graphically below, the idea is the same, easier operation, corresponding button menu, so I don’t need to elaborate

  • This article only provides guidance and introduction. If you encounter scenarios or problems not encountered in this article, please verify them by yourself before performing actual operations, such as Baidu, Google, Bing, etc

  • Practice is key, command line prompt is key

  • Finally, you need to know git first, understand the principle, know the branch usage, to better understand Git SVN;

The background,

Because of the company’s code base, there are now two in parallel, SVN and GitLab, but as everyone knows, once you get used to the way Git works, it’s hard to go back. Every time you use SVN, you want to create a branch, do your own, etc., which also causes problems for testers. In the spirit of solving problems, I decided to study the linkage tools provided by Git itself.

Introduction to Git-SVN

  • 1, the introduction

If you are ok with English, you can read the official Git-SVN

Git-svn is a bidirectional operation provided by Git, that is, you can use it to incorporate the SVN code into git management, and use git to operate the code locally. Finally, the code to be submitted to SVN is submitted from git library to SVN library through related commands.

  • 2. Operation Steps:

2.1 Overview of operation commands

  • 2.1.1 Description of related commands
The serial number The command instructions
1 Git SVN Clone Clone a Git repository from the SVN to the local server
2 git svn rebase Synchronize the SVN code modification to the local branch
3 git svn dcommit Local changes are submitted to the SVN
4 Git add (./changed file) Incorporate changes into the staging area
5 git commit Commit staging changes to the warehouse
6 git stash Commit code to the cache queue
7 git stash apply Applies cached data from the cache queue to the local cache
8 Git branch The new branch
9 Git Checkout (branch name) Check out the branch
  • 2.1.2 General operation ideas
  • 1. Clone a Git-managed repository using git SVN
  • 2. Make code changes and other changes locally, and pay attention to branching
  • 3. Submit the modified code to the SVN

Personal advice:

(1) A small number of changes can be attempted by using git stash to temporarily store the change code. After the changes on SVN are synchronized, the changes can be restored and then synchronized to SVN —-> Corresponding exercise Scenario 3 (2) For large changes, it is recommended to keep the master branch clean and keep only the master branch synchronized from SVN (i.e., Merge or rebase changes to the master branch (note: synchronize updates on SVN before merging), and then synchronize them to SVN. —-> Corresponding to Exercise Scenario 4

Note: Update the SVN before merging

Note: Update the SVN before merging

Note: Update the SVN before merging

Important things say three times!!

  • 2.1.3 Some practice scenarios can be practiced in local simulation scenarios, and can be applied according to their own needs after being familiar with them

Writing in the front

  • 1. The following scenarios have prerequisites. Please read the scenario description
  • 2. The following practice scenarios may correspond to the operations in different scenarios in your actual application. Please consider and use them accordingly
  • 3. If you encounter other problems, please read the related command line instructions and solve them by yourself or baidu (you may encounter a record mismatch problem during record synchronization. You may need to use git rebase command to analyze the problem according to the specific scenario.)

Scenario 1: Create a Git SVN library and submit the modified code. Note This scenario is ideal. It assumes that no new users submit changes on the SVN during the modification.

// Select an address from the SVN and run the git SVN commandcloneTo the local Git SVNcloneChange the content locally and submit git add./changed file git commit -m"Caption"// Run the git-svn command to commit the modification to the SVN library git SVN dcommitCopy the code

Scenario 2: After a period of time, the Clone repository is modified during operation, and then the code is modified through git SVN repository.

Git SVN rebase // After updating remote resources, modify local files and submit git add./changed file git commit -m"Caption"// Run the git-svn command to commit the modification to the SVN library git SVN dcommitCopy the code

Scenario 3: Local code is changed and updates are found on the end before committing

Git SVN rebase // Then remove the changes from the stash stash apply. /changed file git commit -m"Caption"// Run the git-svn command to commit the modification to the SVN library git SVN dcommitCopy the code

Scenario 4: Keep the master branch clean, communicate with the SVN library synchronously, and modify the code in other branches

/ / based oncloneChangeBranch // Change the code on the changeBranch and submit git add./changed file git commit -m"Caption"Git checkout master git SVN rebase Git merge changeBranch // Commit final changes to SVN git SVN dcommit Once you have done this, you will find that the changeBranch branch is no longer useful. You can delete it to avoid confusing git branch after development iterations-d changeBranch  


Copy the code

2.2. Example Operations

Only simple scenarios are listed here (exercise scenario 1). The rest of the scenarios can be implemented by yourself

1. Clone a SVN repository address to the local server using git-svn, for example

git svn clone http://XXXXXXXXXXXXXXXXXXXXXXXX-gitSvn

Copy the code

As shown in the figure above, clone projects synchronize code notes in the SVN library with git library.

2. Modify and submit the code after clone to the local warehouse

The commands here are only for demonstration purposes. For detailed use, you need to understand the relevant commands and then operate them

// Modify the contents of the file; Git add./ git commit -m"Submit content..."Git SVN dcommitCopy the code

Iii. Development mode (personal opinions are for reference only)

Step 1: Create a repository: Use Git SVN Clone

Step 2: Create a change branch, newBranch, in the local repository

Step 3: Modify the code in newBranch and synchronize the code on the SVN on the master

Step 4: After the newBranch is developed, switch back to the master branch to synchronize the CHANGES on the SVN

Step 5: Locally merge the newBranch changes to the master branch

Step 6: After the conflict is resolved, submit the changes on the master to the SVN.

Four, notes

  • 1. Ensure that the branch synchronized on the SVN is clean, usually the master branch.
  • 2. Pay attention to the synchronization timing of the SVN code
  • 3. Pay attention to branch management
  • 4. Pay attention to the prompt information on the command line
  • 5. Rehearse or practice before you are sure what the phenomenon is

Reference Resources:

GitRebase command

Git is introduced

Git – SVN tutorial

Git-svn collaboration official