What is SVN
SVN full name: Subversion, is an open source version control system
Svn is a centralized file version management system . The core of centralized code management is the server . Before starting a new day's work, all developers must obtain code from the server, then develop, and finally resolve conflicts and submit.
Centralized file version controller: All files are handed over to the server for unified management. Since there is a server, it needs to be connected to the Internet to operate.
Why use SVN
When we write a project, it is usually written by a team. If we do not use SVN, then we can only copy each other's code in the team to complete our project .
SVN also has the following benefits:
- Easily compare the subtle differences between different versions [modify the code, there is a version number, and you can know the data before and after the modification]
- Keep abreast of the progress of other members of the team [if the code is not submitted to the server, it is slow to do]
- Wide area network sharing [you can code sharing when you connect to a local area network]
- Work collaboratively to greatly improve team work efficiency
Quick introduction to SVN
Configuration library
There is a concept of configuration library in SVN, so what is it? ?
It stores all the data, and the configuration library stores the data in the form of a file tree
- Include directories and files
Any number of clients can connect to the configuration library, read and write these files . And can add read and write logs , and authorized users can easily see these changes
working copy
We already know from above that we can get the desired file from the configuration repository. Then we have to download the file from the configuration repository. This downloaded area is the working copy .
This working copy is actually the area where we work . After we modify those files, we can submit them to the configuration repository again .
SVN commands
Let's simply learn a few SVN commands. SVN has the function of a graphical interface, so command learning is not necessary. Learn about....
---创建服务器端版本库
svnadmin create 版本库路径
---启动SVN服务器端
svnserve -d -r 版本库路径
---在系统服务中注册svn服务器
sc create svn binPath= "C:\Program Files\TortoiseSVN\bin\svnserve.exe --service -r D:\itcast\svnserver\20150118svn" DisplayName= "svn服务"
---删除系统服务中的 服务
sc delete 服务ID
If you start the SVN server, it will start normally without reporting an error .
assign permissions
Find the svnserve.conf configuration file under the conf folder in our configuration library. Uncomment the following three lines
Assign users
Find passwd under the conf file and configure the user
common subcommands
- import: Commit files or directories that are not included in the version controller into the repository (execute only once)
- checkout: checkout the working copy from the repository tag
- revert: restore the working copy file to the specified version
- update: merge changes from the repository into the working copy
- commit: Commit the changes to the working copy to the repository.
Use SVN
Add data to SVN
To create a configuration library, we can use the command line method or the UI click method. Here I use the UI method directly.
Then, start our SVN service
Put a folder into the configuration repository and let it be managed by SVN
See what we added in SVN:
View specific logs
It is very clearly marked:
Export data from SVN
Export SVN data to users.
After export: this local folder is actually our working copy!
Modify the data exported by SVN and add it back to SVN
I added a file to the working copy
Add to SVN:
Subsequently, it becomes a blue icon + sign, and we submit.
conflict resolution
We may have a problem like this: our SVN is being developed by a team. But before the commit, someone modified the file I was editing. So when I submitted it, there was a conflict [the current data is inconsistent and conflicted]
The localhost2 user exported the SVN data and modified the file:
Another user localhost is also modifying the file, but it is not doing updata operations. Not knowing that the file has been modified.
When he finished the modification and wanted to update to SVN, he found a conflict.
In the face of conflict, we have two options:
- Abandon this modification
- Check what the content of the conflict is, and then decide which data you want when you are finished, or merge it.
We go to the conflicting page and decide which row of data we want
After making the final changes, click Save.
Advice on conflict
- Before modifying the file, perform an update operation first
- After the modification is completed, commit in time, do not stay locally for a long time
- When collaborating with multiple team members, try to revise the parts written by yourself, and try not to revise the parts that are not written by yourself
- Conflicts are normal and can be resolved by the previous method, do not overwrite each other
work flow chart
If there are any mistakes in the article, please correct me, and we can communicate with each other. Students who are accustomed to reading technical articles on WeChat and want to get more Java resources can follow WeChat public account: Java3y