The main content
Introduce the SVN
Introduction to the
Subversion SVN is an open source version control system. Subversion was developed by Collabnet Inc in 2000 and is now a project of the Apache Software Foundation, as well as part of a rich community of developers and users.
SVN is an open source version control system that manages data that changes over time. The data is housed in a central repository. The archive is much like a normal file server, except that it remembers every file change. This allows you to revert to an older version of the file, or to view the history of the file. To put it simply SVN is for multiple people working on the same project and sharing resources.
The main role
- Directory versioning
Subversion implements a “virtual” version-managed file system that tracks changes to the entire directory over time. Directories and files can be versioned.
- Real version history
In Subversion, you can add, delete, copy, and rename any file or directory. All newly added files start with a new, clean version.
- Automatically submit
A commit action is either completely updated to the archive or not updated at all. This allows developers to set up and commit changes in logical intervals to prevent problems when partial commits are successful.
The basic concept
- Repository: A place where source code is stored uniformly
- Checkout: When you don’t have the source code in hand, you’ll need to check it out from Repository
- Commit: When you have modified your code, you need to Commit to Repository
- Update: When you have checked out the source code, you can Update it to the Repository source code
The working process
Start your day
1. Download the latest code of the project team from the server. 2. If you have checked out and someone has committed the code, you can update it to get the latest code. (Update)
Go to your own branch, work on it, and submit code to your own branch every hour (many people have this habit). This is what happens when you change the code and you want to go back to the previous hour or see what you changed in the last hour. (Commit)
4, the time to go off work is coming, merge their branches into the main branch of the server, a day’s work is completed, and reflect to the server. (Commit)
Note: If two programmers make changes to the same file at the same time, _SVN can merge the changes made by both programmers. In fact, SVN manages source code on a behavioral basis, meaning that if two programmers do not make changes to the same one-liner, SVN will automatically merge the two changes. If it is the same line, SVN will prompt the file to Confict, conflict, need to manually confirm. _
The life cycle
Creating a repository
A repository acts as a centralized repository for all of the developer’s work. Repository can not only store files, but also contain the history of each modification, that is, the history of changes for each file.
The Create operation is used to Create a new repository. In most cases this operation will only be performed once. When you create a new repository, your version control system asks you to provide information to identify the repository, such as the location where it was created and the name of the repository.
Check out the
The Checkout operation is used to create a working copy from a repository. A working copy is a developer’s private workspace where content changes can be made and then committed to the repository.
As the name implies, the UPDATE operation is used to update a repository. This operation synchronizes the working copy with the repository. Since the repository is shared by the entire team, your working copy will expire after others have committed their changes.
Let’s assume that Tom and Jerry are two developers on a project. They also checked out the latest version from the repository and started working. At this point, the working copy is fully synchronized with the repository. Jerry then did his work efficiently and committed the changes to the repository.
At this point Tom’s working copy expires. The update operation will pull Jerry’s latest changes from the repository and update Tom’s working copy.
Once checked out, there are a number of actions you can take to implement the changes. Editing is the most common operation. You can edit existing files, such as add/delete files.
You can add files/directories. These added directories, however, do not immediately become part of the repository. Instead, they are added to the list of pending changes until the COMMIT is performed.
Similarly you can delete files/directories. The delete operation immediately removes the file from the working copy, but the actual deletion of the file is simply added to the list of changes until the COMMIT is performed.
The Rename operation changes the name of the file/directory. The move operation is used to move files/directories from one location to another in the repository.
Review of the change
When you check out the working copy or update the working copy, your working copy is fully synchronized with the repository. But when you make some changes to the working copy, your working copy will be newer than the repository. It is a good practice to review your changes before committing them.
The Status action lists the changes made in the working copy. As we mentioned earlier, any changes you make to the working copy will become part of the changelist. The Status operation is used to view this list of pending changes.
The Status operation simply provides a list of changes, but does not provide detailed information about the changes. You can use the diff operation to see the details of these changes.
Let’s say you made a lot of changes to the working copy, but now you don’t want them. The revert operation will help you.
The Revert operation resets the changes made to the working copy. It can reset one or more files/directories. Of course it can also reset the entire working copy. In this case, the revert operation will destroy the list of pending changes and restore the working copy to its original state.
Resolve the conflict
Conflicts can occur when merging. The Merge operation automatically handles things that can be safely merged. Anything else would be considered a conflict. For example, the “hello.c” file is modified on one branch and deleted on another. This situation needs to be dealt with. The Resolve operation is used to help users find conflicts and tell the repository how to handle them.
Commit the changes
The COMMIT operation is used to move changes from the working copy to the repository. This action modifies the contents of the repository, and other developers can view these changes by updating their working copy.
You must add files/directories to the changelist before committing. The list records the changes that will be committed. When committed, we usually provide a comment explaining why the changes were made. This comment will also become part of the repository’s history. COMMIT is an atomic operation, meaning either a complete Commit succeeds or a failure rollback. The user will not see half a successful submission.
Install the configuration
Finally, download the completed installation package
Installing VisualSVN Server
- Double-click the installer visualsvn-server-4.2.1-x64.msi
- Check the check box to agree, then select Next, and select Upgrade
- Select the default configuration and select Next
- Set the installation path of the server, the storage directory and port of resources
- Using the default configuration, select Next
- If this popover appears, select Ignore to Ignore it
- Wait for the installation to complete, check the check box, and then select Finish
- If the following window appears, the installation is successful
- Double-click the installer on TortoiseSVN-18.104.22.168686-x64-svn-1.13.0.msi
- Select Next, then Command Line Client Tools, and select Next
- If you want to install TortoiseSVN on the TortoiseSVN button, click Command Line Client Tools
- If you want to Install TortoiseSVN, click on the Install button
- After the installation is complete, simply select Finish
- In any blank space, right click, the following content appears, the installation is successful
Note: the server side needs to provide IP, port, account, password for the client to use. It has the following configuration
Set the IP and port
- Open the Server, click VisualSVN Server and select Configure Authentication Options…
Set the Server Name. It is recommended to use the current IP
The Server name can be set to 22.214.171.124.1 (locally accessible only) 2. By default, you can view the current IP: Open the DOS window (Windows+R key), type ipconfig, and press enter
New account password
- Right-click on the left-hand menu User and select Create User
- Set the user’s account and password
The new grouping
- Right-click Group and select Create Group…
- Set the group name, and add users to the group
Use the SVN
- Select Repositories, and select Create New Repository…
- Select Default Settings, Select Next, and Set the Repository Name
- Set the repository directory (select any option)
- Set access to the repository (here set read/write access for all SVN users)
- Warehouse creation completed
Checking in the project to SVN (import)
- Copy the address of the remote repository
- Select any project, right click on it and select Import from TortoiseSVN
- Paste the warehouse address copied in the previous step into the address bar
- Choose Permanent Acceptance
- Enter the user account and password
- Import success
- Right-click warehouse, select refresh, and see the effect in server
Check out the item.
- Copy the remote address of the project to download
- In the directory where you want to retrieve the item, right-click and select SVN Checkout…
- Enter the remote address to set the location of the project
- Retrieve complete
Commit the code
- If you want to TortoiseSVN, right click on the file and select Add to the repository
- Click on the file again, right click, and SVN Commit…
- Submitted successfully
Update the code
- If the current resource is not the latest version, you can right-click in a blank space in your project and select SVN Update
- The update is successful
Version conflict problem
Cause of version conflict
Suppose that both users A and B update the file kingtuns.txt when the version number is 100. User A submits kingtuns.txt to the server after the modification, and the submission is successful at this time, and the version number of kingtuns.txt has already changed to 101. At the same time, user B made modifications to the file Kingtuns.txt with version 100. After the modifications were completed, the submission failed because the modifications were not made on the latest version 101. User B updates the file, and if User B and User A modify the same line of code in the file, there will be A conflict
Version conflict phenomenon
When a conflict occurs, Subversion saves all versions of the object file (the last updated version, the currently obtained version (that is, the version submitted by someone else), its own updated version, and the object file) in the current working directory.
Assume the file name is kingtuns.txt
The corresponding file names are:
Changes from different users are also marked in the target file.
Version conflict resolution
- Now both users A and B are updating the project files locally.
- The original contents of the hello.txt file in the project were:
- User A modifies the file and adds the content “User A modifies the content” and submits it to the server after completion
- User B modifies the file and adds the content “User B modifies the content”, which is submitted to the server after completion
- B The user is prompted as follows when submitting the update to the server
- B When you submit files to the server, you will be advised that the version is expired: You should first update the version from the repository, then resolve the conflict, then perform SVN Resolved, and then check in to the repository. After the conflict is resolved, Subversion will need to be informed of the conflict resolution using SVN Resolved so that updates can be submitted.
Three options for conflict resolution
- Discard your update, use SVN Revert (roll back), and commit. No SVN Resolved required in this manner
- Give up your own updates and use someone else’s. Overwrite the target file with the most recently obtained version, perform Resolved Filename and commit (select File — Right — Resolve).
- Manual resolution: When conflicts occur, manually update the target file after communication with other users. Then execute the Resolved Filename to resolve the conflict, and finally commit.
Resolve the conflict
- In User B’s current directory, right-click and select “SVN Update” to perform the “Update” operation
- A conflict occurred in the hello.txt file in user B
- On the file in conflict (select File – Right-click Menu – TortoiseSVN – Edit Conflicts)
Open the Edit Conflicts window
The possessory window is the current latest version on the server, the Mine window is the local modified version, the Merged window is the Merged file contents
- To Use the server version, select the difference content in the possposser window, right-click, and select Use this text block.
Similarly, if you want to Use a local version, after negotiation, right-click on the Mine window and select Use This Text Block.
- When you’re done, select ‘Mark as Resolved’, then ‘Save’ and close the window
- At this point, the current conflict is resolved and you can again select “SVN Commit” to Commit the file
Note: If you want to delete a file from the folder you want to use, click — right button — TortoiseSVN — Resolved. If you want to delete a file from the folder you want to use — Resolved Then you submit the document.
How to reduce the complexity of conflict resolution
- Submit documents as soon as they are edited. Frequent submissions/updates reduce the probability of conflicts occurring and the complexity of resolving them when they do occur.
- When submitting, write a clear message so that you can find out the reason for the user’s update later. After all, as time goes by, the reason for the original update may be forgotten
- Develop a good habit of using SVN every time is to submit, then update. When you open it every morning, you first need to get the latest version from the repository. All edited documents must be submitted to the repository before the end of the day.
The IDEA integration uses SVN
Configure the SVN environment
- File — > Other Settings (global configuration; Settings is local) — > Version Control — > Subversion
When you TortoiseSVVN is in the folder you want to use, you need to add command line client tools to the Settings as well
- Restart the Idea
Retrieve the project
- Select VCS — > Checkout from Version Control — > Subversion
- Add the URL of the item in the remote repository
- Click the added URL and select Checkout
- Select the location of the retrieved item
- Select Destination to your preferences, default to other configurations, and click OK
- Select 1.8 Format and click OK
- Have checked out an item, select Yes to open it
- Select Add
- At this point, the project can be associated with the remote repository
- Select VCS — > Commit…
- Select the file to Commit, fill in the Commit information, and select Commit
- After successful submission, the submission status will be displayed at the bottom of IDEA
Note: It is best to update the project before submitting it.
Update the code
- Select VCS — > Update Project…
- Default is fine, select OK directly
- Update the successful message
Import the project
- Select VCS — > Import into Version Control — > Import into Subversion
- Select “+” to add the address of the project import (you can manually add a folder, the files in the project will be placed in this folder, the file name is customized)
- Select the path to Import, and select Import
- Select the project to import, and click OK
- Check the path of the import, fill in the import information, and select OK
- Check whether the import was successful in the remote repository.
Version conflict problem
- If the resource is not updated and commits (it has been committed by another user), the commit fails
- At this point, an update operation is performed to update a resource that has been committed by someone else to the local area, indicating a conflict
- Select Merge, then the code that you want to keep, and then Apply
- Updated Successfully
- Select Commit again and the conflict has been successfully resolved