Welcome toTencent Cloud + community, get more Tencent mass technology practice dry goods oh ~

This article was published in the cloud + community column by Tencent Worker Bee

Introduction:

Starting from the comparison between Git and SVN, this paper introduces how to start using Git through Git-SVN, and summarizes the common Git commands frequently used in daily work.

Git vs SVN

Everyone has a different experience of Git versus SVN.

Git is distributed, SVN is centralized

This is the biggest difference between Git and SVN. If you can grasp this concept, you can basically understand the difference between the two. Because Git is distributed, it allows you to work offline, and you can do a lot of things locally, including branching, which is coming in a big way. The SVN must be connected to the Internet to work properly.

Git has many complex concepts and SVN is simple and easy to use

All at the same time grasp the Git and SVN developers must be admitted that the Git command is really too much, daily work need to master the add, commit, status, fetch, push, rebase, etc., to grasp skilled, also must grasp the difference between rebase and merge, Fetch and pull. In addition, there are cherry-pick, submodule, stash and other functions. Just these nouns sound very complicated.

In terms of ease of use, SVN is much better, simple and user-friendly for beginners. However, on the other hand, more Git commands means more functions. If we can master most of Git’s functions and understand its secrets, we will find that we can never go back to the era of SVN.

Git branches are cheap, SVN branches are expensive

Branching is a very common feature in version management. Before the release of the version, it is necessary to release branches to carry out large requirements development, feature branches are needed, and large teams will also have development branches and stable branches. In large team development, there is often a need to create branches and switch branches.

The Git branch is a pointer to a commit, while the SVN branch is a copy directory. This feature makes branching in Git very fast and very cheap to create.

Git has a local branch, but SVN has no local branch. If you use Git, you can create a local branch to store the unfinished code, and then go back to the local branch to finish the code.

2. Git core Concepts

One of the most central concepts in Git is workflow.

  • A Workspace is the actual directory on your computer.
  • A staging area (Index) is similar to a cache area that holds your changes temporarily.
  • A Repository is divided into local and remote repositories.

The hardest and least understood aspects of switching from SVN to Git are staging and local repositories. Once you’re comfortable with Git, you’ll find that this is a godlike design that makes a lot of work manageable.

Submission code is usually broken down into several steps:

  1. git addCommit from workspace to staging area
  2. git commitCommit from staging area to local warehouse
  3. git pushorgit svn dcommitCommit from local repository to remote repository

In general, remember the following commands and you’ll be ready to go about your daily work (image courtesy of web site) :

Git-svn common commands

Note This command is intended for developers who use Git-SVN.

If the SVN is used on the server but you want to experience local branches of Git and offline operations, you can use the Git-SVN function.

Common operations are as follows (pictures come from network) :

Download a SVN project and its entire code history, Git SVN info $Git SVN info $Git SVN fetch # $git SVN rebase $git SVN rebase $git SVN rebase $SVN copy [remote_branch] [new_remote_branch] -m [message] [remote_branch]Copy the code

Initialization

Starting from this section, the following commands apply to Git and Git-SVN unless otherwise specified.

[Git only] $Git clone [url]Copy the code

Five, configuration,

$git config --global alias.co checkout $git config --global alias.ci commit $git Config --global alias.st status $git config --global alias.br branch $git config [--global] user.name "[name]" $ git config [--global] user.email "[email address]"Copy the code

The Git user’s configuration file is located in ~/.gitconfig

The configuration files for a Git repository are located at ~/$PROJECT_PATH/.git/config

6. Add and delete files

$git add. $git add <file1> <file2> $git rm [file1] [file2] $git rm [file1] $git rm [file2] $git mv [file-original] [file-renamed]Copy the code

Add the file name file1 to the.gitignore file and Git will stop tracking file1.

Seven, branch

$git branch [branch-name] $git branch [branch-name] $git checkout -b [new_branch] [remote-branch] $git merge [branch] $git merge [branch] $git cherry-pick [commit] $git branch -d [branch-name] # $git push [remote] :[remote-branch]Copy the code

Eight, submit

$git commit -d $git commit -d $git commit -d $git commit -- amend-m [message] # $git push [remote] [remote-branch]Copy the code

Nine, the pull

$Git remote $Git remote $Git remote $Git remote $Git remote $Git remote add [url] $Git remote add [url] $Git remote add [url] $Git remote add [url] $Git pull [remote] [branch] $Git pull [remote] [branch] $git pull --rebase [remote] [branch]Copy the code

Ten, cancellation

$git checkout [file] $git checkout [commit] # $git reset [file] $git reset [commit] # reset the HEAD of the current branch to commit. $git reset --hard [commit] # create a commit Commit $git revert [commit] # Restore the stash contents to the current workspace $git Stash popCopy the code

Xi. Query

$git diff --cached [file] $git diff --cached [file $git log -p [file] $git show [commit]Copy the code

Xii. Others

Write in the back

From SVN to Git, in addition to the basic concepts and common commands listed in this article, including but not limited to how to switch from SVN server to Git server, branch model management is also very important. This article is limited in space, for not introduced but very important knowledge points will be listed in the reference materials, hope as an extension of this article reading.

Machine learning in action! Quick introduction to online advertising business and CTR knowledge

This article has been authorized by the author to Tencent Cloud + community, more original text pleaseClick on the

Search concern public number “cloud plus community”, the first time to obtain technical dry goods, after concern reply 1024 send you a technical course gift package!

Massive technical practice experience, all in the cloud plus community!