current position:Home>The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking

The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking

2022-01-27 02:21:51 Mingjin

【 Madness theory Java】Git The latest course is easy to understand

【 Madness theory Java】Git The latest course is easy to understand

Video sync notes : Crazy talk Git:

One 、 version control

What is version control : Version of the iteration , The new version !

version control (Revision control) It is used to manage our files in the development process 、 Revision history of contents such as catalogues or projects , Easy to view change history , Backup to restore previous versions of software engineering technology .

  • Realize cross regional and multi person collaborative development
  • Track and record the history of one or more files, organize and protect your sources
  • Code and documentation
  • Statistical workload
  • Concurrent development 、 Improve development efficiency, track and record the whole software development process
  • Lighten the burden on developers , Save time , And reduce human error

In short, it is the technology used to manage multi person collaborative development projects .

There is no version control or the version control itself lacks correct process management , Many problems will be introduced in the process of software development , Such as the consistency of software code 、 Redundancy of software content 、 The materiality of software process 、 Concurrency in software development 、 Security of software source code , And the integration of software .

Whether it's work or study , Or take your own notes , Have experienced such a stage ! We urgently need a version control tool !

For multiplayer development, you must use version control , It will cost a lot !

Common version control tools

  • Git
  • SVN( Subversion )
  • CVS( Concurrent versions System )
  • VSS( Micorosoft Visual SourceSafe )
  • TFS ( Team Foundation Server )
  • Visual Studio Online

There are so many version control products ( Perforce、Rational ClearCase、RCS ( GNU Revision Control System ) 、 Serena Dimention、SVK.BitKeeper、Monotone、Bazaar、Mercurial、SourceGear Vault ), Now the most influential and widely used is Git And SVN

Version control tools

1、 Local version control

Record every update of the file , You can take a snapshot of each version , Or record patch files , Suitable for personal use , Such as RCS.


2、 Centralized version control ( Such as SVN)

All version data is saved on the server , Co developers can synchronize updates or upload their own modifications from the server


3、 Distributed version control ( Such as GIT)

Everyone has all the code ! Safe hidden trouble !

All version information warehouses are synchronized to each local user , This allows you to view all version history locally , Can submit offline locally , Only when connected push To the corresponding server or other users . Because every user has all the version data , All data can be recovered as long as there is no problem with one user's device , But this increases the local storage footprint .

No server damage or network problems , Cause a situation that doesn't work !


4、Git And SVN The difference between

SVN It's a centralized version control system , The version library is centralized on the central server , And at work , They use their own computers , So first get the latest version from the central server , And then work , After finishing the work , You need to push your work to the central server . The centralized version control system must be networked to work , The demand for network bandwidth is high .


Git Distributed version control system , No central server , Everyone's computer is a complete version library , You don't need to be connected to the Internet when you work , Because the versions are all on your own computer . The collaborative approach is like this ︰ For example, I changed the files on my computer A, Other people also changed the files on the computer A, At this time , You two just need to push each other's changes , You can see each other's changes .

Git It is the most advanced distributed version control system in the world .

Two 、Git The history of

Like many great things in life ,Git Born in a time of great strife and innovation .

Linux The kernel open source project has a large number of participants . Most of Linux Kernel maintenance is all about the hassle of submitting patches and archiving (1991-2002 Year ). To 2002 year , The whole project team started to use a proprietary distributed version control system BitKeeper To manage and maintain the code .

Linux There are a lot of big guys in the community ! Crack research BitKeeper !

here we are 2005 year , Development BitKeeper The same as the commercial company Linux The partnership with the kernel open source community is over , They took it back Linux The kernel community is free to use BitKeeper The power of . This forces Linux The open source community ( especially Linux The architect of the Linus Torvalds) Based on the use of BitKeeper The lesson of time , Develop your own version system . That is to say, later Git !

Git It is the most advanced distributed version control system in the world .

Git It's free 、 Open source , first Git It's to help Linux Kernel developed , To replace BitKeeper !


3、 ... and 、GIt Basic use of

1、 Software download

open [git Official website ], download git The version of the corresponding operating system . If everything downloads slowly, you can find the image !

Download is too slow on the official website , We can use Taobao image to download :

install : Without brains, the next step is ! After installation, you can use !

start-up Git

After successful installation, there will be... In the start menu Git term , Under the menu are 3 Procedures : Right click any folder to see the corresponding program !


Git Bash : Unix And Linux Style command line , Most used , The most recommended

Git CMD : Windows Style command line

Git GUI: Graphic interface Git, It is not recommended for beginners to use , Try to be familiar with common commands first

Basic Linux command

1 )、cd: Change the directory .

2 ) 、cd .. Go back to the previous Directory , direct cd Go to the default directory

3 ) 、 pwd: Display the current directory path .

4 ) 、Is(ll): List all the files in the current directory , It's just I( Two ) The list is more detailed .

5 ) 、touch: Create a new file, such as touch index.js A new one will be created in the current directory index.js file .

6 ) 、rm: Delete a file , rm index.js It will index.js File deletion .

7 ) 、mkdir: Create a new directory , Just create a new folder .

8 ) 、rm -r: Delete a folder , rm -r src Delete src Catalog

9 ) 、mv Moving files , mv index.html src index.html It's the file we're moving , src It's the destination folder , Of course , Write it like this , It must be in the same directory .

10 ) 、 reset Reinitialize terminal screen clearing .

11 ) 、 clear Clear the screen .

12 ) 、 history View command history .

13 ) 、 help help .

14 ) 、 exit sign out .

15 )、# Notation

Four 、Git Environment configuration

Git To configure

All configuration files , All saved locally

Check the configuration git config -l

1 )、Git\mingw64\etc\gitconfig : Git Install under directory gitconfig --system The system level

2 )、C:\Users\Administrator\.gitconfig Only for the configuration of the currently logged in user --global

You can edit the configuration file directly here , After setting through the command, it will respond here .


View different levels of configuration files :

#  Check the system config
git config --system --list

#  View the current user (global) To configure 
git config --global --list

Set user name and mailbox ( User ID )

Git Related configuration files :

1 )、Git\etc\gitconfig : Git Install under directory gitconfig --system System level configuration files


2 )、C:\Users\Administrator\.gitconfig Only for the configuration of the currently logged in user --global


Here you can edit the configuration file directly , After the command is set, it will respond here .

When you install Git The first thing to do is to set your user name and e-mail Address . This is very important , Because every time Git This information is used for all submissions . It's embedded forever in your submission :

git config --globa1 " Mingjin " # name 
git config --globa1 user.emai # mailbox 

Just do this once , If you pass on –global Options , because Git This information will always be used to handle what you do in the system, using different names or... In a particular project e-mail Address , You can run the command in the project without –global Options . It is not always added to the specific configuration of a project .

5、 ... and 、Git How it works

Work area

Git There are three working areas here ∶ working directory (Working Directory )、 Temporary storage area (Stage/Index)、 The repository (Repository or Git Directory). If you add remote git Warehouse (Remote Directory) It can be divided into four working areas . The conversion relationship of the file in these four areas is as follows :


  • Workspace : work area , It's where you usually store project code
  • Index / Stage: Temporary storage area , For temporary storage of your changes , In fact, it's just a document , Save the information to be submitted to the file list
  • Repository : Warehouse area ( Or local warehouse ), It's where data is stored safely , Here's the data you submitted to all versions . among HEAD Point to the latest version put into the warehouse
  • Remote: Remote warehouse , The server that hosts the code , It can be simply considered that a computer in your project team is used for remote data exchange .

The three local areas should be git Warehouse HEAD Pointed to version :


  • Directory: Use Git Manage a directory , It's a warehouse , Including our workspace and Git Management space .
  • WorkSpace: Need to pass through Git Directories and files for version control , These directories and files make up the workspace .
  • git: Deposit Git Directory of management information , Automatically create when initializing the warehouse .
  • Index/Stage: Temporary storage area , Or call the update area to be submitted , In submit to enter repo Before , We can put all the updates in the staging area .
  • Local Repo : Local repository , A local version library ;HEAD Will be just the current development branch ( branch ).
  • Stash : hide , It's a working state storage stack , Used to hold / recovery WorkSpace The temporary state of .


git This is the general workflow of ︰

1、 Add... To the working directory 、 Modify file ;

2、 Put the files that need version management in the staging area ;

3、 Submit files from staging area to git Warehouse .

therefore ,git There are three states of managed files ︰ The modified (modified) , Temporary storage (staged), Has been submitted (committed)


6、 ... and 、Git Project structures,

Create working directory and common instructions

working directory (WorkSpace) It's usually what you want Git Help you manage folders , It can be the directory of your project , It can also be an empty directory , It is not recommended to have Chinese . Just remember the figure below for daily use 6 An order ︰


Local warehouse building

There are two ways to create a local warehouse ︰ One is to create a new warehouse , The other is to clone the remote warehouse .

1、 Create a new warehouse , Need to use GIT Root execution of managed projects :

#  Create a new one in the current directory Git The code base 

git init

2、 After execution, you can see , Only one more in the project directory .git Catalog , All the information about the version is in this directory .

Clone remote warehouse

1、 Another way is to clone a remote directory , Because the warehouse on the remote server is completely mirrored to the local !

#  Clone a project and its entire code history ( Version information )
git clone [url]

2、 Go to gitee perhaps github Clone a test on !

7、 ... and 、Git File operations

file 4 States

Version control is the version control of files , To modify the file 、 Submit and other operations , First of all, you need to know what state the file is currently in , Otherwise, you may submit documents that you don't want to submit now , Or the documents to be submitted are not submitted .

  • Untracked: No trace , This file is in the folder , But didn't join in git library , Do not participate in version control .. adopt git add The status changes to staged
  • Unmodify: The documents have been put in storage , not changed , That is, the content of the file snapshot in the version library is exactly the same as that in the folder . There are two places for this type of document , If it's modified , And into Modified. If you use git rm Move out of the repository , Then become untracked file
  • Modified: The document has been modified , Just modify , There is no other operation . There are two places for this document , adopt git add Can enter temporary storage staged state , Use git checkout Then discard the modified , Back to unmodffy state , This git checkout That is, take the file out of the library , Overwrite current changes !
  • Staged: Staging status . perform _git commit Then synchronize the changes to the library , At this time, the files in the library and the local files become consistent , File for unmodify state . perform git reset HEAD filename Cancel staging , The file status is Modified

View file status

It says the file has 4 States , You can view the status of the file through the following command :

# View specified file status 
git status [filename]

# View all file status 
git status 
#  Add all files to staging area 
git add .

#  Submit the contents of the staging area to the local repository -m Submission of information 
git commit -m

Ignore files

Sometimes we don't want to include certain files in version control , Like database files , The temporary file , Design documents are established in the main directory ".gitignore" file , This file has the following rules :

1. Ignore empty lines or pound marks in files (#) The beginning of the line will be ignored .

2. have access to Linux wildcard . for example ︰ asterisk (*) Represents any number of characters , question mark ( ? ) Represents a character , square brackets ([abc]) Represents the range of optional characters , Curly braces ({string1,string2,…}) Represents an optional string, etc .

3. If there is an exclamation mark at the front of the name ( ! ), An exception rule , Will not be ignored .

4. If the name is preceded by a path separator (/), Indicates the file to be ignored in this directory , Files in subdirectories are not ignored .

5. If the last side of the name is a path separator (/ ), Indicates that the subdirectory of this name under this directory is to be ignored , Not documents
( The default file or directory is ignored ).

# For comment *.txt
# Ignore all .txt Final document , In this way, upload will not be selected !
# but 7ib.txt With the exception of 
# Just ignore... In the root of the project TODo file , Not including other directories temp
# Ignore build/ All the files in the directory 
doc /* .txt
# Will ignore  doc/notes.txt But does not include doc /server/arch.txt

8、 ... and 、 Use code cloud

1、 Sign up for the login code cloud , Improve personal information


2、 Set native binding SSH Public key , Realize password free login !

#  Get into C: \users \Administrator\.ssh Catalog 
# Generate public key 
ssh -keygen
ssh-keygen -r -rsa

3、 Put the public key information public key Add it to the code cloud account !




4、 Use code cloud to create your own warehouse !


license : Whether open source can be reproduced at will , Open source but not commercially available , Cannot be reproduced ,… Limit !


Clone locally !


IDEA Integrate Git

1、 New projects , binding git.


observe idea Changes in


2、 Modify file , Use IDEA operation git.

  • Add to the staging area
  • commit Submit
  • push To remote warehouse

3、 Submit test


Nine 、Git Branch

Branches in GIT It's relatively difficult , The branch is the parallel universe in science fiction movies , If two parallel universes don't interfere with each other , That has no effect on you now . however , At some point in time , The two parallel universes merge , We need to deal with some problems !



git Common instructions in branches ∶

#  List all local branches 
git branch
#  List all remote branches 
git branch -r
#  Create a new branch , But still in the current branch 
git branch [branch-name]
# Merge the specified branch to the current branch 
git merge [branch]
#  Delete the branch 
git branch -d [branch-name]
#  Delete remote branch 
git push origin --delete [branch-name]
git branch -dr [remote/branch]

If multiple branches are executed in parallel , Will cause our code not to conflict , That is, there are multiple versions at the same time

web-api-A ( Restful.xx() )

web-admin -B Would call A( Revised A Code for !)

web-app -C Would call B and A Code for

If there is a conflict, we need to negotiate !

If the same file is modified when merging branches, it will cause conflicts ∶ The solution is that we can modify the conflict file and submit it again ! Choose whether you want to keep his code or your code !

master The main branch should be very stable , To release a new version , Generally, it is not allowed to work on it , Generally speaking, work in the new dev Work on branches , After work , For example, it will be released , Or say dev After the branch code is stable, it can be merged into the main branch master come up .

copyright notice
author[Mingjin],Please bring the original link to reprint, thank you.

guess what you like

Random recommended