Git-SVN knowledge Summary

Source: Internet
Author: User
Tags svn update how to use git using git
Overview

First, let's briefly introduce the differences between git and SVN. I think the important parts are as follows:

  1. Git is a distributed version control system. This is very different from SVN's central control system. The most significant differences are:

    • Git commit is only sent to the local repo. if the local repo has an upstream Repo, you must manually send it back to the upstream to send the local change back. that is to say, the local repo will not affect the upstream.
    • Because it is distributed, the local repo has all history.
    • Because the local repo has all history, all operations are performed locally and the speed is fast ~
    • In addition to syncing with upstream Repo, you will not be using the network for other times. This means that you can perform commit on your car, on the plane, and in the hot springs in the mountains, and wait until there is a network before synchronization.
  2. Git Branch (Branch) features are super easy, and merge features are super powerful. SVN uses directory as its branch. although it is more convenient than CVs, it is also misused by many people. I have seen several times that someone else has crossed the branch directory in the commit program at work.
Preliminary settings

Before getting started, the system needs to install git and git-SVN. for this part, I believe that there should be a truck article. in addition, all UN * X systems should provide kits for installation, which should not be too difficult.

After the program is installed, clone the svn repo you want to use. if SVN repo uses the directory structure recommended by svnbook, it should have the structure of svn_url/{trunk, branches, tags. the command will be:

Git SVN init-s svn_url {target_dir}

Where{Target_dir}The directory name of the local disk. If your situation is complex, seeGit SVN -- HelpSee what parameters can be used.

Note that the following sections describe branches based on SVN repo with a standard directory structure. If your SVN repo is not the same (is someone doing this ?), Then you have to study how to use git to manage SVN repo.

This step will clone the svn repo. depending on the size of SVN Repo, this step may take several minutes or weeks (Yes, I ran for more than a week ). after that, you should have a git repo with the upstream SVN repo ready for use. available

Git SVN info

Check the svn repo information corresponding to this git repo.

Now you can use

Git Branch

Check the current git branch. there should be only a master. this is the trunk corresponding to SVN repo. in principle, I will only map the master to the trunk of SVN. I used to switch it to different SVN branches, and once it caused a serious problem, a bunch of commit disappeared. after repairing it for a long time, I picked up all the lost commit. the following method has not encountered any problems since I used it for more than a year. as long as you observe it well, I think there should be no major problems.

Basic Process

Do not bother to write it step by step.

Git SVN rebase # update git log -- name-status # similar to SVN log-v. look at the commit log. # edit the GIT diff Program # Check the changed git add-I # select the file for commit. -I: Very convenient ~ Git commit # commit back to * local * git repo # repeat the action between the editor and commit git SVN rebase # synchronize with upstream SVN repo. Conflict should be fixed ~ Git SVN dcommit # Send the local commit back to SVN Repo

It should be mentioned that git is located between repo and working copy, and there is another stage. You need to put the file of COMMIT in working copy, first throughGit addAdd stage, and then useGit commitChange the variable commit in the stage back to git Repo. I would suggest usingGit add-IProvide interactive command columns to add files to stage, which is convenient.

SVN repo Branch

Unfortunately, we cannot completely discard SVN. We recommend that you use SVN to create the svn branch.Git SVN BranchYes, but I do not recommend it.

In addition, SVN. Git cannot be used for the branches of merge SVN. The main reason is that git-SVN does not maintainSVN: Merge-Info. This is very important in SVN!

However, there are not many cases of establishing branches with merge SVN. The vast majority of use cases are still the basic process. We can still use git to synchronize the upstream SVN branches.

InitialGit clone-SThe Branch and tag will be copied together. We can use

Git branch-R

Let's take a look at the branches of the upstream SVN. However, it lists * All * branch names that have been used before, so we still need to useSVN ls svn_url/branchesTo see which branches are currently available.

Determine which SVN repo to use. Next, switch to use it. Assume that the branch name is Branch:

Git checkout-B svn-branch remotes/Branch

Now we have created a local git branch. Its name isSvn-branchThe upstream is SVN.BranchBranch, and we switched to the svn-branch. The next basic process will all happen inSvn-branchAnd upstream synchronization will also be sent to the branch Branch:

Git SVN fetch -- all # capture the updates of the upstream SVN repo * All * git SVN rebase # synchronize the updates of the upstream SVN repo git log -- name-status # Close to SVN log-v. look at the commit log. # edit the GIT diff Program # Check the changed git add-I # select the file git commit for commit # commit back to * local * git repo # repeat the actions between the editor and commit git SVN rebase # synchronize with the upstream SVN repo. conflict to be repaired ~ Git SVN dcommit # Send the local commit back to SVN Repo

Please note that there are moreGit SVN fetch -- all. All updates of the upstream SVN Repo, including updates of each branch, will be captured only on the local end, and will not be merged to the current git repo.Git SVN rebaseCommand will be merged to the current git Repo. UseGit SVN fetch -- allThe reason is that there may be merge between branches, Git-SVN will be automatically found, and the association between them will be established.

Create a local git Branch

As mentioned above, git's branch function is very powerful. Using git instead of its branch function is a waste. XD

This section will be followed by SVN branch because I will introduce my usual naming method. it allows me to know the source of the branch as long as I look at the branch name to determine where merge is going after the branch is completed, reducing the chance of making mistakes.

The naming method is simple. It consists of three parts:

{Source_type}-{name}-{source}

Where:

  • {Source_type}:GitOrSVNIndicates the upstream repo.
  • {Name}: Branch name. It basically describes what the branch is going to do.
  • {Source}: Which branch is created from.

The establishment of git branches is in principle:

  • Svn -*The Branch has one-to-one correspondence with the branch of the upstream SVN.
  • Git -*-*It should be localSvn -*And then create it.

Let's take a look at several examples:

  • Svn-branch: This is a branch corresponding to the branch of the upstream SVN.
  • Git-greatidea-trunk: This is a branch created from the local git trunk branch named greatidea. The SVN branch corresponding to it isTrunk. RememberMasterAlways correspondsTrunk?
  • Git-refactor-branch: This is from the localSvn-branchThe Branch is created, which is called the refactor branch.

So the GIT branch process is:

Git checkout svn-branch # assume that we are currently using SVN-branchgit checkout-B Git-refactor-branch # create a git branch using the epala command # edit the GIT diff Program # See What git add has been changed -I # select the file git commit for commit # commit back to * local * git repo # repeat the action between the editor and commit git checkout svn-branch # Prepare merge to return to svn-branchgit merge Git-refactor-branch # mergegit log -- name-status # Check whether merge has a problem git branch-D Git-refactor-branch # Remove the branch you just created # The following is the same as "SVN Repo"

git mergeConflicts may occur. Remember to usegit add,git commitManually commit in.

Usegit branch -DForce remove branch because of the previous stepgit mergeOnly merge commit is required, but merge point is not marked yet. when the branch is removed, a warning "the branch is not merge" appears. in fact, we should not mark the merge point with git. Otherwise, returning the svn repo will become a commit with no changes, but it will be more troublesome.

Git-SVN simple tutorial: SVN is a centralized version control system, while git is a distributed version control system... so the best way is not who replaces it... they work collaboratively.
You can use git SVN (note that some versions do not have Git-SVN ).

1. Create a local directory. For example, if myproject is used
$ Mkdir myproject
$ CD myproject

2. initialize and obtain a version
$ Git SVN init http: // XXXX <= SVN repository path
$ Git SVN fetch-r XXXXX <= get a version (there is a space between-R and XXXXX. If no version is specified, it will be obtained based on the svn record level 1)

(Update Thu Nov 26 09:45:36 CST 2009)
The above two steps can also be taken in one step, that is

$ Git SVN clone http: // XXXX myproject

(Update on: If the remote SVN repo is standard, you can use the $ git SVN clone http: // xxxx/svn xxxx -- username XXX @ xxx-s Google code example)

Then, we usually perform local operations... In addition,

Git SVN rebase can update local files (similar to SVN update)
Git status = SVN status
Each operation, git will prompt you accordingly.
Git config -- global core. whitespace-trailing-space (GIT intelligence to a certain extent, if your programming habits are not good, it will also give a warning, such as the end of this line of the program contains spaces. you can set to remove the warning)

Finally, if you want to submit, use
Git SVN dcommit

Kdebase this is good: http://techbase.kde.org/Development/Tutorials/Git/git-svn

 

Update on 2012-03-20:

To keep an empty folder, place a. gitignore in the folder with the following content: (from: http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository)

# Ignore everything in this directory

*

# Upload t this file

!. Gitignore

Update on 2011-07-21:

To ignore some files, you must first:

Git config -- global core. excludesfile ~ /. Gitignore

Then edit VI ~ /. Gitignore.

For example, if you need to ignore the vim temporary file, write:

. *. SWP

Git-SVN usage and problems in use (resolved)
    SVN was used in previous projects. When I was working on Git-SVN today, I encountered a problem and recorded it for future query.
    Usage process:
    1. Clone the project from SVN, add the-S parameter to mark and identify the svn standard directory branch structure, and set the exclude attribute of the GIT library through show-ignore: Java code
    1. Git SVN clone-s https://svn.xxx.com/svn/xxx
    2. Git SVN show-ignore>. Git/INFO/exclude

    2. Create a local work branch and start working: Java code

    1. Git checkout-B Work

    The modification content is directly commit, and the entry starting with-a is used to omit the GIT add operation: Java code

    1. Git commit-

    3. Process of submitting back to SVN: Java code

    1. Git checkout master
    2. Git merge work
    3. Git SVN rebase
    4. Git SVN dcommit

    In my work today, I submitted back to SVN in the following way: Java code

    1. Git checkout master
    2. Git SVN rebase
    3. Git merge work

    As a result, SVN rebase generates a new node on the master branch. In this way, merge cannot be merged quickly and conflicts occur. After the fix, an error occurs during dcommit, N isolated nodes are displayed. Because I am not familiar with it, I have checkout out of the Work Branch, performed dcommit, and then re-generated the GIT library.

    (Updated in 7/14)
    Solve this problem today, refer to the following url: https://wiki.bnl.gov/dayabay/index.php? Title = synchronizing_repositories.
    The following describes the problem and solution:
    1. the following error occurs when running git SVN dcommit:
    Commit to https://svn.xxx.com/svn/projects/trunk...
    Merge conflict occurred when submitting: Your file or directory "test/functional/xxx_controller_test.rb" may be outdated: The version resource does not correspond to the resource within the transaction. either the requested version resource is out of date (needs to be updated), or the requested version Resource
    Is newer than the transaction root (restart the commit). at/usr/bin/Git-SVN line 450

    2. In this case, re-execute the following steps: Java code

    1. Git SVN fetch
    2. Git SVN rebase
    3. Git SVN dcommit

    However, a conflict occurs when I execute git SVN rebase. In this case, I only need to manually merge the conflicts and add the following again: Java code

    1. Git add.

    Then execute: Java code

    1. Git rebase -- continue

    If the report says no changes are made, execute the following code: Java.

    1. Git rebase -- skip

    After the rebase process is completed, you can use git SVN dcommit.

    In this way, the svn history conflicts are finally solved, and you don't have to re-Git-SVN clone as stupid as you did before.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.