You can see it when using svn for the first time

Nowadays, general development is collaborative development, so a version control system is used. To put it bluntly, everyone develops a project together, writes different codes separately, and then needs to bring the codes together. Everyone may need the code written by each other, that is Everyone writes a set of code together, which requires a version control system to store the code everyone writes in one place, which is equivalent to a backup server!
The mainstream version control systems now are Git and SVN, and Git seems to be more popular. Of course, many companies use SVN. Several companies I have currently experienced are using SVN, so this article will go into detail. Introducing the SVN skills and uses that you need to know and that are often used in your work!

First let’s take a look at what SVN is

The following is the explanation from Baidu Encyclopedia:

SVN is the abbreviation of subversion. It is an open source version control system. Through the efficient management of branch management system, in short, it is used for multiple people to jointly develop the same project, realize shared resources, and realize the final centralized management. .
If you still don’t understand, it is recommended to search on Baidu. For example, you can search like this: “What is SVN”. It is recommended to read more on Baidu Encyclopedia and Wikipedia. What is mentioned above is quite detailed!

To use it, you must install it

Let’s talk about the installation on Windows first. 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 your computer. Of course, you can choose to install qq music or It’s NetEase Cloud Music!

Well, SVN also has versions to choose from. On Windows, it is Little Tortoise. This is the alias of this client. It is called “TortoiseSVN”. Because Tortoise means turtle, it is called Little Tortoise. Look at it. icon:

Okay, isn’t it very frustrating? We want to download it: https://tortoisesvn.net/downloads.html

Just choose to install it according to your computer situation!

Here are some things to note:

Just choose this. In addition, after choosing 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 on the first line of the page. Look carefully, then The English paragraph is still understandable, so I won’t post pictures here.

If you need to use the command line, you can choose here:

Then just go all the way next! Then after installation, you can right-click on a folder on your computer and this will appear, which means the installation is successful:

Then you can also do:

This also means it’s OK! Another point, after installation, it is all in English. In fact, you can install simplified Chinese language, but I think it is better to use English. Really, if you can use English, don’t use Chinese, we are advanced programmers!

After installation, start it and see how to use it

The above is all the preparation work. Now that it is done, let’s take a look at how to use it!

svn is a centralized thing
What does it mean? It means that svn has a service center. The overall code is in this service center. Then clients on other computers can link to this center, so that they can pull and submit codes from the center. Drawing The picture probably looks like this:

So, generally if you use svn for collaborative development, you will have a central service code. You don’t need to take care of this. You only need to install the svn client on your computer. The above has already told you how. installed.

Some people may be curious about where this service center is. This is usually an svn server, which also needs to be set up. It can be set up locally or remotely. Companies usually use it remotely, and everyone uses it together. What do you think? Interested, I can write another article to teach you how to set up an svn server!

Start pulling the code (the first important point)

Everything is ready. You have also installed the svn client locally. At this time, someone will give you a project address of the svn server. For example, take the address of the svn server I built locally as an example. Let me show you. It looks like this:

For example, if you are asked to participate in the development of the simplejava project, you will be given an address at this time:

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

You will then be assigned a username and password:

username: user1 password: user1

After getting these, you can pull the code. First, think about where you want to put the pulled code. For example, on the desktop, you can create a new folder called “project”

Then open this folder, then right-click and this will appear, click this:

After clicking, this window will pop up:

What this means is that you have to connect to the svn service center, but you can’t connect casually. You need a username and password. This is given to you. Let’s fill it in. Pay attention to the lower left corner here to see if you remember the password:

In this way, the extraction is successful, but if you look at the extracted code, the project in our service center is called simplejava. In fact, I also want to extract this simplejava. In this way, all the files extracted are the files in the project. How? manage?

Actually you can do this:

When we click on the Choose items, we can see the content of the item we want to pull. At this time, we can remove the name of the item, that is, like this:

In this way, you can see a broader view, then select the item we want to pull, then OK, pull it down and that’s it.

Permission issues

But is this really okay? The answer is that sometimes it’s really not possible. For example, let’s try again:

Okay, this is no problem, let’s try to look at the previous level:

Scream, no, what’s going on? Actually, it’s easy to understand. You can’t just read the code if you want to see it. You can do whatever you want. It’s not the project you’re doing that you should focus on. None, so there is permission here. Take a look at these in the service center:

Each folder here can actually be assigned permissions, that is to say, if you participate in development, an account will be created for you, but your account has read and write permissions, and you can view some. Some you can’t see.

Therefore, sometimes after getting the account and address, you find that there is a problem and you can’t pull the code. Then ask if the permissions have not been opened for you. Sometimes it really is that the permissions have not been opened. I have encountered this. .

How to set permissions and so on, this is the knowledge of svn server. We will not cover it here. We will talk about it when we talk about setting up svn server!

Then you may want to ask, what should I do if I don’t see it? It’s simple. Create the project folder locally first. For example, if you want to pull simplejava, just create one first and then pull it. The same:

Okay, write the code and submit it too

After the above preparations are completed, you should write the code. Come on, open the code we pulled:

We see that there is only one Java class in it. Come on, let’s modify it:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user user1");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Okay, ok, now we have written the code, let’s take a look at the changes:

Look, there is a red exclamation mark here. Is it an error? Actually no, it means that the code has changed. After all, you have added new code. Next, submit your newly added code. You can do this:

Right-click the file that needs to be submitted, and then click commit. The following box will pop up.

Then it’s ok. Check to see if it turns green again.

Add a new thing

Okay, it’s my first submission, and I feel a sense of accomplishment. Let’s take a look. Suppose we add a new Java class. Come on, write one:

Here we create a new User class. In fact, after it is managed by svn, the corresponding representation will be displayed on the file. For example, a normal java file will display a green check mark, but sometimes this There will be problems with the gadget. For example, a newly added file should display a blue question mark on it. The rough identification is like this (for Java files)

Remember, the newly added file is an unknown file, and we need to add it to our repository:

It will be recognized after being added.

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

The submission steps are similar to the above

I want to delete a file, what should I do?

Sometimes you may need to delete a file, such as deleting the User you just created. We can do this:

What should you do if you suddenly regret it after deleting it? You press Ctrl + Z on the keyboard hard, but it seems to have no effect. You need to do this:

Remember, you click on the blank space, but if you really want to delete it, after you delete it through the above operation, the files in the service center are still not deleted. You still need to submit, click on the blank space, and select Submit:

This time it was successfully deleted!

Why can’t I submit it (update code)

We use svn for collaborative development, which means that you are not the only one writing these codes, but others are also writing them. For example, others have modified Test1, such as this:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user user1");
        System.out.println("Say hello, I am user ithuangqing");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

You see, this is new code added by another person. Now if you look at your code, yours still looks like this:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user user1");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

For example, you start modifying this code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user1, study hard and make progress every day!");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Then you also start submitting, but you see

I went and reported an error. What should I do? Come, first translate a sentence into English:

Do you know what’s going on? It’s just that the code on the server has changed. What you have here is not the latest. 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 learn svn!");
        System.out.println("Hello everyone, I am user1, study hard and make progress every day!");
        System.out.println("Say hello, I am user ithuangqing");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

See if there is code added by user ithuangqing, and then submit it. This time it is guaranteed to be successful!

Let me go, what is the conflict about?

One problem you will definitely encounter in collaborative development is conflicts. Generally speaking, you and others have modified the code at the same location. Let’s look at an example:

First, someone else modified this line of code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user user1, study hard and make progress every day! -- Stop studying, you will never learn, haha");
        System.out.println("Say hello, I am user ithuangqing");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Then you also modify this line of code:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Welcome to learn svn!");
        System.out.println("Hello everyone, I am user1, study hard and make progress every day! It is so difficult");
        System.out.println("Say hello, I am user ithuangqing");
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

What you need to figure out here is that the person above has modified this code and submitted it. Instead of updating it first, you directly modified the code. Then you started to submit and found this error:

This question has been mentioned before, so let’s update it. The result:

This creates a conflict, which is actually easy to understand. You both modify this code. The other person’s code has been submitted, and you update it. It is equivalent to pulling down this line of code on the server, and then you find that you have also modified it. So it’s all over, who made the correct changes? Which one should be left behind?

At this time, the conflict needs to be resolved. At this time, you can look at the file:

What is this? This is because a conflict has arisen and you need to resolve the conflict. How to resolve it? Let’s open the source file and take a look:

At this time, you need to deal with which piece of code should be left. This needs to be discussed with others to see where the problem is. Let’s take a look at the final decision on which piece of code to leave. For example, in the end, your own modification is correct. Yes, then delete these:

Then it becomes like this:

Then you look at these files:

Hasn’t the conflict been resolved? Yes, you resolved the conflict, but you did not tell svn. You have to tell svn that the conflict was resolved. Do this:

Then this:

Click OK to completely resolve the conflict:

After the conflict is resolved, you can submit your changes normally! (The previous submission was unsuccessful and needed to be updated. The update encountered a conflict. After the conflict was resolved, there was no problem in submitting again)

View log

Logs must be paid attention to in future development. In this svn, we can also view logs. For example, we can view the logs of this class:

Here you can see some modifications to this file made by yourself and others.

Version rollback requires attention

This function is also used a lot, but it may feel a little confusing at first. For example, when we are writing code, we later find that there is a problem with the code we wrote, and the result has been submitted, and someone else pulls our code, then There must be something wrong, what to do? At this time, we can use version rollback to see how to operate.

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

Then we also submitted it, how did we fix it, I regretted it, can we go back in time, and if someone updates the code, it will be updated to my error code. Look, this is what it looked like:

Then someone updated it, and it looks like this:

It’s a slap in the face, no, I have to get rid of my own error code. How to do it, that is, version rollback, look at:

Then select the version you want to roll back:

Then you look again and you will see that the previous error code is no longer there.

Attention, attention, attention!

When you write wrong code and submit it, other people’s updates will be updated to your code. But at this time, you may be the only one who knows that there is a problem with this code, and you want to rewrite it. Then just like the above, you roll back the version. , the previous error codes are gone, you can rewrite it, but if others update now, they will still get your previous error codes.

So at this time you need to commit and restore the submitted error code on the svn server to the original version. Remember to commit after rolling back!

If you do not commit after rolling back, but continue to write the correct code, it will be another situation (if you do not commit, there is no real rollback, local rollback, but not the remote server). At this time, when you put the correct code After the code is written and submitted, you will be prompted to update it. Once you update it, a conflict will occur with your previous wrong code. At this time, you need to resolve the conflict, leave the correct code, and then submit it. , then others will get your correct code when they update again.

Is there a better way

The error caused by the above kind of rollback is to use this rollback method:

In actual testing, it will appear that new code is written without committing after the rollback. When submitting, an update will be prompted, and the update will conflict. However, if you use this method to roll back:

After instant rollback, you can write new correct code without committing, and the submission can still be completed by committing again. You will not be prompted to update like the above, and then there will be conflicts in the update!

As for why this situation occurs, I have not conducted in-depth research. I will continue to share it if necessary later!

Summary

Regarding the use of svn, it is enough for a friend who has just joined the company and is using svn for the first time. The main thing is to understand some operational concepts, and then be proficient in updating and submitting. Generally, update before writing code to avoid conflicts. The other more important thing is to check the information again when encountering new problems in actual use or ask others to solve them quickly and accumulate experience quickly!