[Git] Quick start installation and use &The difference between git and svn&Common commands

1. Introduction

1. What is svn?

        SVN is the abbreviation of Subversion and is a centralized version control system. Unlike Git, SVN does not have distributed features. In SVN, the project's code repository is located on the server, and team members implement version control by submitting and obtaining code to the server. SVN records the modification history of each file, including information such as author, time, and specific changes.

        When using SVN, team members need to check out the latest code of the project from the central code repository and develop and modify it locally. Once the work is completed, they push the code back to the central code repository to share the changes. SVN provides a series of commands and functions, such as updating code, submitting code, viewing history, comparing file differences, etc., so that team members can work together and manage code versions. However, because SVN is centralized, team members may not be able to commit or get the latest code when the network connection is interrupted or the server fails.

1.1. Advantages of svn

  1. Easy to use: Compared with Git, SVN’s commands and operations are relatively simple, and the learning curve is relatively gentle. For some developers with non-technical background or who are new to version control, it is easier to get started using SVN.
  2. Centralized management: SVN adopts a centralized working method. All codes are saved on the server side, which can centrally manage and control code access rights, making it convenient for team collaboration and code control. Quality and safety.
  3. Security: Since all codes are saved on the server, the risk of local code loss is avoided, and administrators can manage and monitor the operations of each user, ensuring the security of the code. safety.

1.2. Disadvantages of svn

  1. Network connection required: Since SVN is centralized and needs to interact with the central code repository, a stable network connection is required. If the network is interrupted or the server fails, the latest code cannot be submitted or obtained, affecting the development process.
  2. Does not support offline work: SVN needs to interact with the remote server, and developers cannot modify and submit code offline, which limits their freedom in environments without network connections. Development capabilities.
  3. Complex branch management: Compared with Git, SVN's branch management is relatively complex. The creation, merging, and deletion of branches require manual operations and may present some conflict resolution challenges.
  4. Low storage efficiency: Since SVN adopts a difference-based version control method, only the changes made are saved for each submission, and the storage efficiency is relatively low. Especially in large-scale projects, it takes up a large amount of storage space.

2. What is Git?

        Git is adistributed version control system used to manage and track software development projects source code. It can record historical changes of the entire project, including modifications, additions and deletions of each file, as well as information such as the author and time of each submission. By using Git, team members can work together and share code, with the ability to easily undo or roll back changes, resolve merge conflicts, and automatically identify and handle code updates. Git also provides branching functionality, allowing developers to work on independent branches and finally merge the branches into the mainline. This makes it easier and safer for multiple people to work on the same project at the same time.

2.1. Advantages of Git

  1. Distributed version control: Git is a distributed version control system. Each developer can have a complete copy of the code base and can work offline. This allows team members to develop and submit changes independently without being affected by network connectivity or server failures.
  2. Powerful branch management: Git’s branch management function is very powerful and flexible. Developers can easily create, merge and delete branches to achieve independent development and parallel work. This is very beneficial for team collaboration and when multiple features or fixes are being worked on in parallel.
  3. Fast operation and high performance: Since Git stores a complete copy of the code locally, code can be quickly viewed, submitted, and switched locally. Compared with centralized version control systems, Git operations are usually faster, especially in large projects.
  4. Rich tool ecosystem and community support: Git has a large user base and an active open source community, providing a wealth of tools and extensions. There are also many third-party tools and services, such as GitHub, which provide functions such as code hosting, collaboration, and Code Review.

2.2. Disadvantages of Git

  1. The learning curve is steep: Compared with centralized version control systems such as SVN, Git has a steep learning curve. It has many advanced functions and commands, and for beginners, it may take some time and effort to become familiar with and master.
  2. High storage usage: Since Git stores a complete copy of the code, each submission will increase the consumption of storage space. Especially when the project history becomes large, more disk space requirements will occur.
  3. With power and flexibility comes complexity: Git’s power and flexibility can make it complex and difficult to understand. For example, branch merging and conflict resolution may require some skill and experience to handle.

3. Difference

        Git has advantages over SVN indistributed features, branch management and powerful version control capabilities. However, SVN is still widely used in some scenarios due to its simplicity, ease of use and centralized nature. Choosing which version control system to use depends on the needs of the project, the team's workflow, and the developer's preferences. There are some significant differences in their design thinking and working methods.

  1. Distributed vs Centralized: The most obvious difference is that Git is a distributed version control system, while SVN is a centralized version control system. In Git, every developer has a complete copy of the code repository and can work offline and submit changes. The code repository in SVN is located on the server, and developers work by submitting and obtaining code to the server.
  2. Version management method: Git saves different versions of the code in incremental snapshots. Each submission will create a new snapshot and record the reference relationship of the parent snapshot to build Create a directed acyclic graph of commit history. SVN adopts a difference-based approach and only stores the differences of each submission. Compared with Git, SVN uses storage space more efficiently.
  3. Branch management: Git's branch management is very flexible and powerful. It can easily create, merge and delete branches, and supports the existence of multiple independently developed branches at the same time. The branch management of SVN is relatively simple, usually requiring manual creation of branches, and merging branches is more complicated.
  4. Performance: Because Git has a complete copy of the code repository, it can provide faster operation speeds in large projects. SVN's performance on large-scale projects may be limited by network connectivity and server performance.

Here is a difference as I understand it:

  1. Decentralization
    1. GIT is distributed, SVN is not: This is the core difference between GIT and other non-distributed version control systems, such as SVN, CVS, etc.     
  2. Any copy of the git repository can be used independently as a server
  3. There are four states of files in Git:
    1. Untracked: Indicates that the file is newly added
    2. Modified: Indicates that the file has been modified but has not been saved to the git repository.
    3. Staged (staged): Indicates that the current version of a modified file has been marked to be included in the next submitted snapshot
    4. Committed: Indicates that the file has been saved in the git warehouse.
  4.  Others
    1. GIT does not have a global version number, but SVN does: By far this is the biggest feature that GIT lacks compared to SVN.
    2. GIT's content integrity is better than SVN: GIT's content storage uses the SHA-1 hash algorithm. This ensures the integrity of code content and reduces disruption to the repository in the event of disk failures and network problems.
  5. Record snapshots directly, not differences
    1. GIT stores content as metadata, while SVN stores content as files: all resource control systems hide the metainformation of files in a folder like .svn, .cvs, etc.
  6. Record snapshots directly, not differences
    1.      GIT branches are different from SVN branches. Branches are nothing special in SVN. They are just another directory in the repository.
  7. There are branches in git.

2. Use of git

1. Create a warehouse

  1. Enter workbench - Gitee.com official website to log in and register.
  2. Click on the homepageCreate warehouse, after filling in the formCreateThat's it.
    1. Warehouse name and Path should be filled in according to your own, as well as these twoPath a> be filled in. Must
    2. If you are a novice, I recommend selecting Open Source here.

2. Install Git on Windows

EnterGit - Downloads (git-scm.com)Download version 2.22 or above.

[Note] Do not install onC drive(win10 may have permission issues ).

  1. After the download is complete, double-click to install and select the installation path.
  2. ①Icons will not be created on the desktop by default, and a new feature has been added
    ②Add GItBash to Windows terminal, it is recommended to check it.
  3. Choose a default editor, the default isVim (Linux), which also has Notepad. I choose to use Vim.
  4. The default name (master) after creating a branch in Git. If there is no special use of the default settings, click next.
  5. The default recommendation is the second one, which does not include all tools. The third one is git and all Unix tools
  6. Turn on the https connection to ensure the security of data transmission. Just follow the default selection.
  7. Additional configuration options are not selected by default. You can check these two boxes to support (node, python) and then select install.
  8. Start git Bash View the release notes. You can leave it unchecked
  9. win + R cmd Input:git --version View version book 
  10. Or if you right-click anywhere on the computer and see these two, it means the installation is successful.

3. Upload the warehouse

  1. Create a new warehouse, remember or save this interface after creation, it will be used.
  2. Create a new folder locally for uploading, right-click Git Bash Here and a command window will appear.
  3. Run the command that appears to create the warehouse once.
    ①Run the first command and a file will appear under your user.
    ②Execute the second box selection command. When we execute the git init command, there will be a hidden folder. After we execute the command A login window will pop up, just log in.

  4. upload completed

Quick upload:

  1. Put our files into the already created warehouse folder
  2. Enter the command in the command window: git add .
  3. git commit -m "Newly submitted file" : You will not be able to see your file in git after submission
  4. git push: push to git

4. Warehouse download resources

  1. Get the address we need to clone.
  2. Create a new folder for cloning.
  3. Enter the command:git clone [url]: Clone the remote repository to local.
  4. Cloning completed

3. Common git commands

Git has many other commands and options available. You can get more detailed command instructions and usage by running git --help or consulting the Git documentation. Here are some common Git commands and their functions:

  1. git init: Initialize a new Git repository.
  2. git clone [url]: Clone the remote repository to local.
  3. git add [file]: Add the file to the staging area.
  4. git commit -m "message": Submit the files in the temporary storage area and add submission information.
  5. git status: View the status of the workspace and staging area.
  6. git log: View commit history.
  7. git branch: View branch list.
  8. git checkout [branch]: Switch to the specified branch.
  9. git merge [branch]: Merge the specified branch into the current branch.
  10. git pull: Pull the latest code from the remote warehouse.
  11. git push: Push local code to the remote warehouse.
  12. git remote add origin [url]: Associate the local warehouse with the remote warehouse.
  13. git diff: View the differences between the workspace and the staging area.
  14. git reset [commit]: Undo the commit and move the HEAD pointer to the specified commit.
  15. git stash: Save the current modifications to a temporary storage area so that they can be applied again after switching branches or restoring.

4. Git common command theory

These commands are the foundation of Git and can help you manage your projects and collaborate with others. When using these commands, you need to understand the theory behind them, including concepts such as version control, branch management, merging, and conflict resolution, so that you can better use Git to manage your projects.

Here are some commonly used Git commands and their theories:

  1. git init: This command is used to create a new Git repository. When you run this command, Git will create a new .git directory in the current directory. This directory contains all the data and metadata required by Git.
  2. git clone: This command is used to clone a Git repository locally. You can use this command to download a remote repository to your local machine so that you can view the project or modify it.
  3. git add: This command is used to add files to the staging area and prepare them for submission. Depending on the status of the target file, the effect of this command is different: you can use it to start tracking new files, or to put tracked files into the temporary storage area. It can also be used to mark conflicting files as resolved when merging. wait.
  4. git commit: This command is used to submit files in the staging area to the warehouse. You can use this command to submit the files in the staging area to your local warehouse.
  5. git push: This command is used to push files in the local warehouse to the remote warehouse. You can use this command to push your local changes to the remote repository so that others can see and share your changes.
  6. git pull: This command is used to pull files from the remote repository to the local one. You can use this command to download the latest changes from the remote repository to your local machine so that you can view and modify these files.
  7. git merge: This command is used to merge two branches. You can merge changes from two branches together with this command.
  8. git rebase: This command is used to apply changes from one branch to another branch. You can use this command to apply changes from one branch to another branch instead of merging the two branches.

Guess you like

Origin blog.csdn.net/weixin_74383330/article/details/134267272