current position:Home>Git tool

Git tool

2022-01-26 22:25:51 X-77

        The previous article introduced npm Tools , This is still a tool ~ This time it's about Git Tools !

Catalog

One 、 What is? GIt

Two 、Git download

3、 ... and 、Git operation

Four 、 summary


One 、 What is? Git

        Git Is an open source distributed version control system , It's the most advanced 、 The most popular version control system .

        characteristic : The bigger the project, the more complex , The more collaborative developers , The more you can show Git Of High performance and High availability .

        characteristic :

        Git Three states of :  

         Git workflow :

                        1. Modify the file in the workspace

                        2. Staging changes you want to commit next time

                        3. Submit update , Find the file in the staging area , Permanently store the snapshot to Git Warehouse

Two 、Git download

        Download address :Git

        After downloading and installing , Right click the blank space , When you see the following message, the installation is successful .

         After installation, we need to make some configuration . Facilitate the follow-up when developing projects with multiple people , Know who modified the workspace file . If used --global Options , You only need to run once , That is, it can take effect permanently .

        git config --global user.name " user name "

        git config --global user.email " mailbox "

        View configuration information :

        git config --list --global( View global configuration items )

        When we need help , have access to git help command , You can open the help manual on the Internet without networking

        git help <verb>   //  Get the full version of the manual

        git <verb> -h      // Get a more concise ”help“ Output

3、 ... and 、Git operation

        git Four states in the workspace :

         1. initialization

        In the project directory ( work area ) Open in "Git Bash", And implement git init The command changes the current directory to Git Warehouse . This command creates a file named .git Hidden directory for , Is the of the current project Git Warehouse , Contains the initial necessary files , yes git A necessary part of the warehouse .

        git init  // initialization Git Warehouse

        here , All files in the workspace are in the unused state Git Tracked files . We can go through git status To check the status of the file .

        git status  // View the status of the file

        git status -s // View the compact status of the file

Show statement State description
?? Not by git Tracked files
A Files newly added to the staging area
M A modified 、 Files not in the staging area
M

A modified , Files that have been put into the staging area

        2. Track new files

        Use git add The command starts tracking a new file .

        git add The role of :

                1. You can use it to start tracking new files
                2. Put tracked 、 And the modified files are put in the temporary storage area
                3. Mark conflicting files as resolved

        When we want to track multiple new files at once / Add multiple modified files to the staging area :git add . 

        Check the status and you can see the following information , It means that it is in the state of being stored in the temporary storage area at this time .

        3. Submit update

        git commit -m  ” Describe the message “// Save the staging area file to Git Warehouse

        After running the statement , Again using git status Check file status , You will find that the following information is returned :

        At this point, it means that all files in the workspace are git track , And save it as a snapshot to git Warehouse .

        When we modify the contents of the file in the workspace , Need to reuse git add Commit the file to the staging area , Reuse git commit -m Command submit update .

        4. Cancel the temporary file

        git reset HEAD Name of the file to be removed   // Restore the file to the state before staging

        5. Skip using staging area

        git commit -a -m ” Describe the message “  // Simplify the workflow : work area -> Git Warehouse

        6. Undo changes to the document

        git checkout -- file name // Undo changes to the document

        7. remove file

        git rm -f file name   // from Git Remove files from warehouse and workspace at the same time

        git rm -cached file name // Remove only Git Documents in storage , Keep files in the workspace

        8. Ignore files

        Some documents do not need to be included Git management , But we don't want them to always appear on the untracked file list . We can create a .gitignore Configuration file for , List the matching patterns of the files you want to ignore .

file .gitignore The format specification of is as follows :

        With # start Note

        With / ending It's the directory

        With / start Prevent recursion

        With ! start Representation inversion  

        have access to glob Pattern to match files and folders

          Example :

         9. View the submission history

        git log     //  View the history of all submissions         

        git log - Numbers // Show the submission history of the specified number of entries

        git log -2 --pretty=online // Display the last two submission history on one line

        git log -2 --pretty=format:"%h | %an | %ar | s "  Show the last two submission history on one line , And customize the output format .

         notes :%h The abbreviated hash value submitted   %an Author's name   %ar Author's revision date , Show... In the way it used to be   %s Submit instructions

        10. Back to the specified version

        Git Each upload is a version snapshot , So we can quickly switch versions .

        git reset --hard <CommitID>  // Submit according to the specified ID Back to the specified version

        When we want to go back to the previous version in the latest version , You need to display the submission history on one line :git log --pretty=oneline sentence . And when we want to go back to the new version in the old version , You need to use another statement to query the history : git relog --pretty=oneline

Four 、 summary

        Git Is a very easy to use version control system , stay git There are many sentences in , One of the most important is initialization Git Orders from the warehouse Commands for viewing file status Command to add files to the staging area as well as Submit files from staging area to Git Orders from the warehouse . If you don't know these four orders, you will be punished to read the article again !

          notice Github Do you feel familiar with ! you 're right , This is the world's best open source project hosting platform , Only support Git As the only version control tool . In the future, we can put the local Git Upload warehouse to Github Study with you on 、 communication .

 Antenna baby monkey king avatar   Teletubbies journey to the West expression pack  ​

copyright notice
author[X-77],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262225466800.html