Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic operations of Git from VSS to SVN and then to Git

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Source code control has always been an important part of the software development process, from the initial pure file backup to the use of tools for management. The role of the Source code control tool is not just to manage the same version. From the current mainstream source code control tools, it is not difficult to find that there are more and more application scenarios of Branch, tag and other functions, especially the agile programming used by most enterprises, combined with branch and tag and other functions can really achieve multi-version development, fast iteration.

Think about how we can quickly develop multiple functions simultaneously based on one piece of code without source code control.

Going back to several source code control tools I used in the industry.

VSS

VSS (Visual Source Salf) is a code management tool provided by Microsoft. As a member of Visual Studio, it does ensure that the code is not modified by developers in the early development process, but also solves the difficulties of code sharing management in remote development cooperation. But there are still some shortcomings, such as:

The file is basically locked in an exclusive situation. If An is modified, B has no way to modify it.

VSS only supports the Windows version, and the supported development tools only support Microsoft.

Based on file storage, the server must share folders. Security is worth considering. It used to be used in intranet development environment.

Charge

SVN

SVN (Subversion), an open source source code control system. Apart from the most basic code management functions such as those provided by VSS, the biggest highlight is the provision of branches, and the level of submission is based on lines of code. In other words, there is no longer the problem of exclusive file development. For example, a code file that implements an interface can be modified by multiple developers at the same time. Whoever does it first can submit it first, and will not wait until all the people have to do it before merging. For engineers who can't use VSS, the emergence of SVN is a complete boon, jumping directly from CVS to such a powerful tool.

To sum up, the advantages and disadvantages of SVN are as follows:

Advantages:

High code consistency.

Support the submission of physical operations.

Diff function.

Branch,Tag reference to facilitate version management.

It's easy to use.

Inferior position

It must be in a networked state before some data can be read.

Is not a distributed code base.

The disaster of a SVN server crash is huge.

Git

With the popularity of the open source movement (thanks to Liunx developers), Git has become popular. Is it said that Git has become popular with the popularity of the open source movement? This is due to the distributed nature of Git. Just imagine, if all the Liunx enthusiasts around the world were developing and submitting on several machines, it would be sour. Or if the main server crashes, other developers will have to burst into tears.

The power of Git lies in the following:

Each time Clone pull everything, including version information, from the server.

Locally, you can create your own branches according to different needs.

Arbitrary switching between branches.

Branch merging can be carried out on a single machine.

Niuren + plug-in blessing. Git flow, a plug-in provided according to the Vincent Driessen branch model.

Git-model@2x.png

A successful Git branching model

How to use Git

Installation

$Brew install git

Create a warehouse

$git init

File operation

With the warehouse, you can perform add, commit, push and pull operations on the files.

TablesAregit add add to staging area git add-interactive Interactive add git apply Application Patch git am Application Mail format Patch git annotate synonym, equivalent to git blame

Git archive file archiving and packaging git bisect binary search git blame file line-by-line traceability git branch branch management git cat-file version library object research tool git checkout check out to the workspace, switch or create branch git cherry-pick submission picking git citool graphical submission Equivalent to git gui command git clean clear workspace untracked files git clone clone version library git commit submit git config query and modify configuration git describe visually display submission IDgit diff difference comparison git difftool call graphical difference comparison tool git fetch to get the patch file of the remote version library submission git format-patch creation mail format. See git am Command git grep File content search and location tool git gui Tcl/Tk-based graphical tool, focusing on operations such as submission git help helps git init version library initialize git init-db* synonyms Equivalent to git initgit log display submission log git merge branch and git mergetool graphical conflict resolution git mv rename git pull pull back the submission of the remote version library git push push to the remote version library git rebase branch change git rebase-interactive interactive branch base git reflog branch reference change record management git remote remote version library management git repo-config* synonym Equivalent to git configgit reset reset change branch "cursor" points to git rev-parse to convert various reference representations to hash values, such as git revert reverse commit git rm delete file git show displays various types of object git stage* synonyms, equivalent to git addgit stash save and restore progress git status display workspace file status git tag milestone management

.

.

Best practice

It is recommended to use github for hands-on experiments. After registering Github once using mailbox, you can create your own Repository on Github.

2.png

After the creation is completed, we will get an address of Repository. With this address, we can practice Git.

3.png

Use git clone to clone the remote repository locally.

Git clone

5.png

Add some files

Echo "Hello Scott"-> "Hello" / / writes a file to Hello git add Hello / / adds the Hello file to the staging area. (Index) git commit-m "this is my first file" / / submit to local warehouse git push / / push local warehouse to remote warehouse

6.png

Above, the files are pushed to the remote warehouse. Other engineers can pull the changed files locally if they perform the Pull operation.

7.png

If another engineer modifies the file, you need to get it remotely.

Git pull / / pull the remote file git log / / to view the change history

A5B85BFD-764E-468F-81C4-0B727BA70428.png

The resolution of conflicts

Conflicts are often caused by inconsistencies in versions. For example, engineer A modifies the Hello file and submits it to the remote warehouse, while B modifies the Hello locally and wants to submit it. Because the Hello files of An and B are not consistent, a conflict occurs.

4EB9EB75-2FF9-4363-AD78-9E13D1415EA8.png

You only need to git pull once. (note: git pull automatically merge, but usually the effect of automatic merge is not very good. For example, both An and B are modifying function A () {}).

The conflict looks like this.

10.png

Generally, after manually resolving the conflict, re-add, submit, and push.

11.png

As described above, merging conflicts manually is cumbersome. It is recommended to use tools for git operations, and now general tools provide branch management, merging and other functions.

Recommend SourceTree

Management of branches

In many cases, you will encounter the need to develop multiple functions at the same time, and the development task will be assigned to multiple engineers for development. at this time, the practice on Git is-- > create multiple branches. N engineers create branches from Master or Dev branches.

After the git checkout-b NewFeature / / branch is built, it will switch directly to that branch. Git push-- set-upstream origin NewFeature / / Associated with remote Branch

After completing the development, you need to merge into the Master or Dev branch.

Git merge origin/NewFeature / / merge the remote branch NewFeature with the current branch.

12.png

Write at the end

The above spread from source code control to the use of Git is just a brick to attract jade. You are welcome to give us your advice.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report