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

What are the differences between Git and SVN

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

Share

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

This article mainly introduces "what are the differences between Git and SVN". In daily operation, I believe many people have doubts about the differences between Git and SVN. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what are the differences between Git and SVN?" Next, please follow the editor to study!

1. Git vs SVN

Which is better, Git or SVN? everyone has a different experience.

Git is distributed, SVN is centralized

This is the biggest difference between Git and SVN. If you can master this concept, you will basically understand most of the difference between the two. Because Git is distributed, Git supports offline work, and many operations can be done locally, including the next major offshoot. SVN must be connected to the Internet to work properly.

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

All developers who master Git and SVN at the same time must admit that there are too many Git commands, daily work requires mastering add,commit,status,fetch,push,rebase, etc., and if you want to be proficient, you must also master the difference between rebase and merge, fetch and pull, etc., in addition, there are cherry-pick,submodule,stash and other functions, but these nouns sound very roundabout.

In terms of ease of use, SVN will be much better, easy to use, and friendly to novices. But on the other hand, more Git commands mean more functions. If we can master most of the functions of Git and realize the secret of it, we will find that we can never go back to the era of SVN.

Git branch is cheap, SVN branch is expensive.

Branching is a frequently used feature in version management. Before releasing the version, you need to release branches, carry out large requirements development, need feature branches, and large teams will have development branches, stable branches, and so on. In the process of large team development, there is often a need to create branches and switch branches.

The Git branch is the pointer to a commit, while the SVN branch is the directory of the copy. This feature makes the branch switching of Git very fast and the creation cost is very low.

And Git has local branches, SVN has no local branches. In the actual development process, we often encounter some code that is not finished, but other problems need to be dealt with urgently. If we use Git, we can create the unfinished code in the local branch, and then go back to the local branch to finish the code after the problem is solved.

II. The core concepts of Git

One of the core concepts of Git is workflow.

The Workspace is the actual directory on your computer.

An Index is similar to a cache area, which temporarily saves your changes.

Warehouse area (Repository), divided into local warehouse and remote warehouse.

Switching from SVN to Git is the most difficult and incomprehensible thing to understand about staging areas and local repositories. After using Git skillfully, you will find that this is simply divine design, and because of the existence of both, a lot of work becomes easy to manage.

Typically, submitting code is divided into several steps:

Git add submits from the workspace to the staging area

Git commit is submitted from temporary storage area to local warehouse

Git push or git svn dcommit submit from local warehouse to remote warehouse

In general, remember the following command to do your daily work (the picture is from the network):

Third, Git-SVN common commands

This section of the command for developers using Git-SVN, please be sure to master.

If the server uses SVN, but locally you want to experience the local branch of Git, offline operation and other features, you can use the Git-SVN feature.

The common operations are as follows (the picture is from the network):

# download a SVN project and its entire code history and initialize it to the Git code base $git svn clone-s [repository] # View the current version of the repository $git svn info# retrieve all branches of the remote warehouse $git svn fetch# retrieve the changes of the current branch of the remote warehouse and merge with the local branch change base $git svn rebase # upload the local warehouse of the current branch to the remote warehouse $git svn dcommit# to pull the new branch And submit it to the remote warehouse $svn copy [remote_branch] [new_remote_branch]-m [message] # to create a local branch corresponding to the remote branch $git checkout-b [local_branch] [remote_branch] IV. Initialization

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

# create a new Git code base in the current directory $git init# download a project and its entire code history [Git only] $git clone [url] 5. Configuration # enumerate all configurations $git config-l# configure aliases $git config-- global alias.co checkout$ git config-- global alias.ci commit$ git config-- global alias.st status$ git config-- global alias.br branch# set the user information when the code is submitted $git config [--global] user.name "[name]" $git config [--global] user.email "[email address]"

The profile for Git users is located in ~ / .gitconfig

The configuration file for a single Git warehouse is located in ~ / $PROJECT_PATH/.git/config

Add and delete files # add all files in the current directory to the staging area $git add. # add the specified files to the staging area $git add. # add the specified directory to the staging area, including its subdirectory $git add # Delete the workspace files, and put this deletion in the staging area $git rm [file1] [file2]. # stop tracking the specified files However, the file will remain in the workspace $git rm-cached [file] # renamed file, and the renamed file will be placed in the staging area $git mv [file-original] [file-renamed]

Add the filename file1 to the .gitignore file and Git will stop tracking the status of file1.

7. Branch # list all local branches $git branch# list all local branches and remote branches $git branch- a # create a new branch, but still stay in the current branch $git branch [branch-name] # create a new branch and switch to the branch $git checkout-b [new_branch] [remote-branch] # switch to the specified branch And update the workspace $git checkout [branch-name] # merge the specified branch to the current branch $git merge [branch] # Select a commit, merge into the current branch $git cherry-pick [commit] # delete the local branch -D parameter forcibly delete branch $git branch- d [branch-name] # Delete remote branch $git push [remote]: [remote-branch] VIII, submit # submit temporary storage area to warehouse area $git commit-m [message] # submit changes to work area and temporary storage area directly to warehouse area $git commit-a # display all diff information $git commit-v# submit temporary storage area modified to warehouse area, merge to last modification And modify the last submission information $git commit-- amend-m [message] # upload the specified local branch to the remote warehouse $git push [remote] [remote-branch] IX. Pull # download all changes to the remote warehouse (Git only) $git fetch [remote] # display all remote warehouses (Git only) $git remote-v # display information about a remote warehouse (Git only) $git remote show [remote] # add a new remote warehouse And name (Git only) $git remote add [remote-name] [url] # to retrieve the changes in the remote warehouse and merge them with the local branch, (Git only). If you use Git-SVN, please see section 3$ git pull [remote] [branch] # retrieve the changes in the remote warehouse and merge with the local branch base, (Git only), if you use Git-SVN Please see section 3$ git pull-- rebase [remote] [branch] X, undo # restore the specified files of the staging area to the workspace $git checkout [file] # restore all files of the current directory of the staging area to the workspace $git checkout. # restore the workspace to the specified commit$ git checkout [commit] # reset the specified files of the staging area, consistent with the last commit, but the workspace remains unchanged $git reset [file] # reset the staging area and the workspace Consistent with last commit $git reset-- hard# resets the pointer of the current branch to the specified commit and resets the staging area, but the workspace does not change $git reset [commit] # resets the HEAD of the current branch to the specified commit, and resets the staging area and workspace, consistent with the specified commit. $git reset-- hard [commit] # create a new commit To undo the specified commit$ git revert [commit] # to place uncommitted changes in the storage area $git stash# to restore the contents of the storage area to the current workspace $git stash pop 11, Query # View workspace file modification status $git status # View workspace file modification details $git diff [file] # View staging area file modification $git diff-- cached [file] # View version library modification record $git log # View someone's submission record $git log-author=someone # View the history of a file Specific changes $git log-p [file] # View a submission of specific changes $git show [commit] to this point The study on "what is the difference between Git and SVN" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report