Front-end and back-end interaction: Git basics

✍Catalogue overview:

1. Git basics

1.1 Version management

1.1.1 What is version management

Versioning is a way of recording changes to a file so that you can refer to a specific version of the file's contents in the future.

1.1.2 The problem of manual maintenance of document version

  1. The large number of documents and unclear naming lead to confusion of document versions

  2. Every time you edit a document, you need to copy it, which is inconvenient

  3. When multiple people edit the same document at the same time, it is easy to overwrite

1.1.3 Version Control

  • Version control is a system that records changes to the contents of a file for future reference to revisions of a particular version.
  • In fact, the most important thing about version control is that it can record file modification history, so that users can view historical versions and facilitate version switching

1.1.4 Version control tool

Version control tools are divided into centralized version control tools and distributed version control tools

  • Centralized version control tool
  • CVS、SVN、VSS
  • Centralized version control systems, such as CVS, SVN, etc., have a single centralized management server that saves the revisions of all files, and people who work together connect to this server through the client to take out the latest files or submit renew. This has been standard practice for version control systems over the years.
  • This practice has many benefits, everyone can see to some extent what everyone else on the project is doing. Administrators can also easily control the permissions of each developer, and managing a centralized version control system is far easier than maintaining a local database on each client.
  • There are two sides to things, good and bad. The obvious downside of doing this is that the central server is a single point of failure. If the server is down for an hour, no one can submit updates during this hour, and they cannot work together.

Please add a picture description

  • Distributed version control tools

    • Git、Mercurial、…
    • For distributed version control tools like Git, the client does not extract the latest version of the file snapshot, but completely mirrors the code warehouse (local library). In this way, if any file used for collaborative work fails, it can be restored using the local warehouse of other clients afterwards. Because each file extraction operation of each client is actually a complete backup of the entire file warehouse.
  • After the appearance of the distributed version control system, the defects of the centralized version control system were solved:

    • Development is possible even when the server is disconnected from the network, because version control is performed locally
    • Each client also saves the entire complete project, which is more secure including historical records

insert image description here

1.2 What is Git

  • Git is aversion control system(abbreviated VCS), it can == save the state of the document as an update record at any point in time, and it can also restore the update record at any point in time.

  • Git is a free, open-source distributed version control system that can quickly and efficiently handle projects ranging from small to large

  • Git is easy to learn, has a small footprint, and has blazingly fast performance. It features cheap native libraries, a convenient staging area, and multiple workflow
    branches. Its performance is better than version control tools such as Subversion, CVS, Perforce and ClearCase.

1.3 Git installation

  • Official website address: http://git-scm.com/
  • * During the installation process, all options can use the default values.

Git and Code Hosting Center

The code hosting center is a remote code warehouse based on a web server, generally we simply call itremote library

1.4 Git basic workflow

git repository storage cache Work list
Used to store submission records Temporary storage of modified files Project directory managed by Git

1.5 Git Common Commands

command name effect
git config --global user.name username set user signature
git config --global user.email mailbox set user signature
git init Initialize the native library
git status View the status of the local library
git add filename Add to staging area
git commit m "log information" file name Submit to local library
git reflog view history
git reset hard version number version shuttle

1. Git configuration before use: set user signature

Before using git, you need to tell git who you are, and you need to use it when submitting to the git repository.

Basic syntax:

  1. Configure committer name:git config --global user.name 提交人姓名
  2. Configure committer name:git config --global user.email 提交人邮箱
  3. View git configuration information:git config --list

And there is a file C:\Users\Augenesternunder .gitconfig, open it and it will be the user signature we set.

Notice

  1. If you want to modify the configuration information, repeat the above command.
  2. Configuration only needs to be done once.
  3. The function of the signature is to distinguish different operator identities. The user's signature information can be seen in the submission information of each version, so as to confirm who made this submission. Git must be installed for the first time to set up a user signature, otherwise the code cannot be submitted.
  4. Setting the user signature here has nothing to do with the account that will log in to GitHub (or other code hosting centers) in the future.

2. Initialize the local library (git init)

Basic syntax:git init

==3、==View the status of the local library (git status)

Basic syntax:git status

  • First time viewing, there are no files in the workspace

3.1. New files

Syntax: vim hello.txt, then press the i key to enter INSERT, if you want to copy and paste, you need to press the esc key first, then yycopy , ppaste

After the file content is entered, you need to press :, enter first wq, and then the new file is completed, and you can check it again

4. Add a temporary storage area (git add file name)

Basic syntax: 单个文件 git add 文件名all files git add .

5. Submit the local library (git commit -m submission information)

Basic syntax:git commit -m "日志信息" 文件名

6. Modify the file

grammar:vim 文件名

7. Historical version

7.1. View historical version (git log)

Basic syntax:

  • git reflogView version information
  • git logView version details

But there is always only one file in hello.txt in our workspace

7.2, version shuttle

grammar:git reset --hard 版本号

8. The principle of switching versions

When Git switches versions, the bottom layer is actually a moving HEAD pointer. The specific principle is shown in the figure below

The HEAD pointer points to the master branch, and the master branch points to the first version

After that, there is a second version, and the master pointer points to the second version

After that, there is a third version, and the master pointer points to the third version

If we want to travel back, we only need to make the master pointer point to the first version or the second version

9. Revocation

  • Overwrite files in the working directory with files in the staging area:git checkout 文件

  • Delete the file from the staging area:git rm --cached 文件

  • Restore the update record specified in the git repository, and overwrite the temporary storage area and working directory:git rest --hard commitID

Guess you like

Origin blog.csdn.net/m0_55990909/article/details/124336880