In the general development are coordinated development, so use a version control system, namely we develop a project together and write different code, then need to code together, you may need each other to write code that is common to write a set of code, this is the need to the version control system, write all the code stored in one place, Equivalent to a backup server!

The mainstream version control systems, now, are Git and SVN, and Git seems to be more popular, of course, there are many companies using SVN, I have experienced several companies are using SVN, so this article will introduce in detail those you need to know, often used in the work of SVN skills and use!

Let’s first look at what SVN is

Here’s what Baidu Baike explains:

SVN, the abbreviation of Subversion, is an open source version control system. Through the efficient management of branch management system, in short, it is used for many people to jointly develop the same project, realize the sharing of resources, and realize the final centralized management.

If you are still a little confused, I suggest you go to Baidu to search. For example, you can search “What is SVN?” I suggest you read Baidu Encyclopedia and Wikipedia, which are quite detailed.

To use it, you have to install it

To put it simply, if we want to use SVN, we need to install a client. For example, if you want to listen to music, you need to install a music software on the computer. Of course, you can choose to install QQ Music or netease cloud music!

Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise Tortoise


Ok, whether very resistant to, we want to download it: tortoisesvn.net/downloads.h…

According to their own computer situation, choose to install!

Here are some caveats:

In addition, after selecting which version to install and download above, remember to select accept in the lower left corner of the page that pops up, and then wait for the download. If there is no download for a long time, you can manually click the link in the first line of the page, look carefully, that English section is still understandable, I will not map here.

If you need to use the command line, here is the option:


And then all the way to Next! Then, after the installation, you can right-click any folder on your computer and see this as a successful installation:


Then you can do it again:


This also means that it is OK! In addition, this installation is in English, in fact, you can install Chinese simplified language, but ye, I think it is still in English, really, can use English do not use Chinese, WE are a lofty programmer ah!

After you install it, do it and see how it works

Above is the preparation work, now well, how to use, let’s have a look!

SVN is a centralized thing

SVN has a service center where the total code is stored, and clients on other computers can link to this center, so they can pull and submit the code from the center.


So, normally if you are co-developing with SVN, you will have the central service code, which you don’t need to do, you just need to install the SVN client on your computer, which is shown above.

May be some curious, where the service center is what ah, this is generally the SVN server, also need to build, can local structures, can also be remote, company usually is remote, all food use together, the that you are interested, I can also teach you how to set up the SVN server write an article!

Let’s start pulling code (first point)

When everything is ready and you have installed the SVN client on your local computer, someone will give you a project address of the SVN server. For example, the address of the SVN server I built on my local computer looks like this:


For example, if you want to work on the SimpleJava project, you will be given an address:

https://LAPTOP-GO8995UD:8443/svn/SVNdemo-ithuangqing/simplejava

You will then be assigned a username and password:

username: user1 password: user1

So once you’ve got that, you can pull code, and the first thing you want to do is think about where you want to put that code, like on your desktop, you can create a folder called project.


Then open this folder, right click this to appear, and click this:

Clicking on it will bring up this window:


You need to connect to the SVN service center, but you can’t connect to it casually. You need the user name and password, which was given to you. Let’s fill in the password, and pay attention to the lower left corner here.


This pulled it off, but if you look at the code that pulled it off, the project in our service center is called SimpleJava. In fact, I want to pull it off too. This is simpleJava.

You can actually do this:


If we click “Choose Items”, we can see that we want to pull and retrieve the content of this item. At this time, we can remove the name of this item, which is like this:


So you can look at the broader picture, and say we want to pull that item, and then OK, pull it down and that’s it

Permission problems

But is it really ok? And the answer is sometimes you can’t, like if we try again:


Ok, that’s fine, let’s try the next level:


Yelling, this is what is going on, in fact, it is good to understand ah, people’s overall code can not say you want to see see ah, let you do what you do, not the project you see no effort, so ah here is authorized, you see the service center these:


In fact, each folder here can be assigned permissions, that is to say, let you participate in the development, you will create an account of your own, but your account is read and write, some you can see, and some you can’t see.

So, sometimes after getting the account and address, find that there is a problem, can not pull the code, then ask whether the permission did not give you open, sometimes it is really the permission did not open, I encountered.

System language how to set permissions what, this is the SVN server this piece of knowledge, we do not involve here, we talk about the SVN server to build time again!

Create a project folder for SimpleJava. For example, to pull simpleJava, create a project folder first and then pull it.

All right, write the code. Let’s submit it, too

Now that you’re done, it’s time to write code. Here, open the code:


We can see that there is only one Java class in it.

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hi, I'm user1."); }}Copy the code

Ok, now we also write code to it, let’s look at the changes:


Look, there’s a red exclamation mark, is that a mistake? In fact, it does not mean that the code has been changed. After all, you have added the new code. Next, you can submit your new code.

Right-click the file you want to commit, and click Commit to bring up the box below


And then it’s ok. Let’s see if it goes back to green.

Add a new thing

Let’s say we added a new Java class. Let’s write a new Java class:


Here we create a new User class, in fact, the management of SVN up after, will again file showing the relative said, due to such as normal to Java file showing a green tick, but, sometimes it will appear problem, such as the newly added a file should be in the above shows a blue question mark, The general notation is this (for Java files)


Keep in mind that the newly added file is an unknown file and we need to add it to our repository:


Once it’s added, it’s recognized


It’s a blue plus, and then we can submit it

The submission steps are similar to those above


I want to delete a file. Why

If you want to delete a file, for example, if you want to delete a User, you can do this:

This time after you delete, suddenly regret how to do? You press Ctrl+Z hard on the keyboard as if nothing is working. You need to do something like this:


If you want to delete the file from the service center, you still need to submit it. Click on the blank and select Submit:


This time successfully deleted!

Why can’t I submit it? (Update code)

We are using SVN for collaborative development, which means that you are not the only one who is writing the code, but someone else is also writing the code, for example, someone else is making changes to Test1, like this:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hi, I'm user1.");
        System.out.println("Wow, I'm user Ithuangqing"); }}Copy the code

You see, this is new code added by someone else, and then you look at your code, and your code still looks like this:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hi, I'm user1."); }}Copy the code

For example, if you start modifying this code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hello everyone, I am user1, good good study day day up!"); }}Copy the code

And then you start submitting, but look


Oh, shit. I got an error. I got an error. What do I do? First, translate a sentence in English:

You don’t have the latest code, you need to update it, so update it:


Then look at the updated code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hello everyone, I am user1, good good study day day up!");
        System.out.println("Wow, I'm user Ithuangqing"); }}Copy the code

Ithuangqing added the code, and then submit it, this will guarantee success!

Oh, my god. What about the conflict

One of the most common problems with collaborative development is conflict, usually when you and someone else change code in the same location. Here’s an example:

First someone else modified this line of code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hello everyone, I am user1, good good study day day up! - Stop learning, you can't learn, ha ha.");
        System.out.println("Wow, I'm user Ithuangqing"); }}Copy the code

Then you also modify this line of code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to SVN!");
        System.out.println("Hello everyone, I am user1, good good study day day up! It's hard to!");
        System.out.println("Wow, I'm user Ithuangqing"); }}Copy the code

Here you need to remember that someone has already modified the code and submitted it. Instead of updating it first, you have directly modified the code. Then you start to submit and find this error:


This issue has been discussed before, so update it. Results:


You both change this code, someone else’s code has been submitted, you update it, you pull down this line of code on the server, and you find that you have also changed it, that’s the end of the world, who changed it right? Which one should you keep?

This is where the conflict needs to be resolved, and this is when you look at the file:


What the hell is this? This is because there is a conflict and you need to resolve it. How? Let’s open the source file and see:


At this point, you need to deal with which part of the code to leave, and this needs to be discussed with others to see where the problem is, and then look at the final decision 6 to leave which part of the code, for example, your own modification is correct, then delete these:


And it went like this:


And then you look at these documents:


Didn’t we resolve the conflict? Yes, you resolved the conflict, but you didn’t tell SVN. You need to tell SVN that the conflict was resolved, like this:


And then this:


Click OK to resolve the conflict:


After the conflict is resolved, you can submit your changes as normal! (The previous submission was not successful, need to update, update encountered conflict, after resolving the conflict, submit again no problem)

See the log

In the SVN, we can also view logs, for example, we can view logs of this class:


Here you can see some of the changes you and others made to this file.

Version rollback is important

This feature is also used more, but began to feel a little confused, for example, we at the time of writing code, then find yourself writing code has a problem, the result has been submitted, others pull my code, it must a problem ah, how make, this time we can use version rollback, look at specific how to operate.

For example, now we need to write a function like this:

Then we also submitted it, how to do, regret, can we go back to the time, when they update the code, they will update my error code, you look at the original is like this:

And then they update it and it looks like this:


No, I have to kill my own error code, which is the version rollback, and watch:


Then select the version you want to roll back:


And then you look at it, and you don’t have the error code anymore.

Attention attention attention!

When you write the wrong code submitted after the update will update to your code, but this time may only you know this code has a problem, and you want to write again, it would be like the one above, your version rollback, before the error code is lost, you can write again, but others now update will still get error code before you.

Commit the error code on the SVN server to the original version. Remember to commit after rollback!

If you don’t commit rollback after, but continue to write the correct code, it would be another situation (not commit is not really a rollback, local rolled back, but not to a remote server), and this time after you finish writing the correct code, submit, it will prompt you to update, once you update, can produce conflict, You need to resolve the conflict, leave the correct code, and then submit it, at this time someone else will update again to get your correct code.

Is there a better way

The error caused by the above rollback is using this rollback method:


In this case, a rollback is performed without a commit, and a new code is written, followed by a commit that prompts an update. The update conflicts occur, but if the rollback is performed this way:


Commit (s); commit (s); commit (s);

As for why such a situation occurs, I have not done in-depth research, and will continue to share if necessary later!

conclusion

About the use of SVN, for a friend who just hired first use SVN has had enough schooling, the main is to understand some operating concept, then master update and submit, general update first, before you write the code to avoid conflict, the more is the new problems encountered in the course of actual use to find information or ask others to quickly solve, Gain experience quickly!

Pay attention to xiaobian public number oh, learn more