This is the 30th day of my participation in the August Challenge
GIT and making
- Before we do that, we need to be clear about a few things
git
和github
It’s two things, not one thing- Just like
java
和javascript
Same thing, two things - Need to make sense of a few words
- Local: my own terminal
- Remote: Terminal at the other end of the network
- Warehouse: a quilt
git
Managed folders
What is a GIT
git
Official name:Distributed version manager- Personal explanation: is a tool to manage our folders
- But you can keep all version information
- That’s when we install a piece of software
- Then use the software to manage one of our folders
- This folder is covered by
git
After management, we can do all kinds of operations on him - Make sure we don’t lose anything we’ve written
What is a lot
github
It’s a website, it’s a platform for us to host projects- It’s one of the world’s largest websites
- That is to say, we write the projectThe source codeCan be put on it to save, as long as we do not delete themselves, will not be lost
- It’s like Baidu Cloud
- Just more powerful and full of developers (world level)
- because
github
We only acceptgit
To upload the code. That’s why it’s calledgithub
- In other words, we can pass
git
This software manages our local folders- And you can upload the code inside the folder
github
save - You can also write a plug-in or something and upload it
github
This is for other developers to use - Can also be from
github
Find plugins written by other developers to download and use
- And you can upload the code inside the folder
- Say so,
github
It’s also a big oneOpen sourceResource sharing platform
Use the GIT
- As we said earlier,
git
It’s a tool to manage our folders - So we need to install the tool first, then use the tool to manage our folders
GIT installed
-
You can download git directly from the official website
- Git website
- Git Download Center
-
Just find the version that corresponds to the operating system
-
Once you’ve downloaded it, just double-click to install it
-
Just go to the next step and install the default path
-
After the installation, check whether the installation is successful
-
Method 1: Open the CMD window and enter commands to check
#Check whether Git is installed $ git --version Copy the code
- If the version number is displayed, the installation is successful
-
Method 2: Right-click the mouse in a random place and the following figure will appear, indicating that the installation is successful
-
- Once installed, we are ready to use it
Use the GIT
-
Git is a piece of software, yes, but it’s not something that makes an icon appear on your desktop
-
It’s software that needs to operate from the command line
-
Let’s right click Git Bash Here
-
The following image appears
-
When we click on it, we find a command line window
-
In fact, it is to write some instructions for us to use, but a little colorful
- use
cmd
orpowershell
Window to rungit
Instructions can also work - As long as it’s terminal running
- The OS operating system runs directly in the terminal
- use
-
Git Bash Here: Run Git Base in the current directory
-
So, in which folder did you click, where is the directory of the command line window that you come out of
-
We use Git to manage our folders from the command line
GIT initialization
-
If you want a folder to be managed by Git, you need to initialize git in a folder
-
Find a folder that you want managed by Git
-
Right click inside the folder and open Git Bash Here
-
Input order
#Git initialization instructions $ git init Copy the code
-
Git folder (this folder is a hidden folder)
-
At this point, my git_demo folder is managed by Git
git
Not only this folder is managed, but all subfolders and subfiles are managed
-
Note: Only after a folder has been managed by Git can you use git’s capabilities for version management
- In other words, we have to authorize a folder on our computer to
git
git
To do anything with the contents of this folder- while
git init
This is the authorization operation
- In other words, we have to authorize a folder on our computer to
GIT the staging area
-
When a folder is managed by Git
-
Git will “partition” the current folder
-
It will be divided into three areas
- Workspace: The source code we write is in the workspace property
- Staging area: Put what we want to store in staging area
- History area: Pull out the contents of the temporary storage area to form a history version
-
That is, we need to put the code we want to be a version of
- Put it in the staging area first
- Then it can be put into history in temporary storage area
- Before you can generate a version to save
-
To put it in staging, use git add
-
Place a single file in the staging area
#Place the index. TXT text in the folder in the staging area $ git add index.txt Copy the code
-
Place a separate folder in the staging area (the staging area cannot store empty folders)
#Place the ceshi folder under the folder in the staging area $ git add ceshi/ Copy the code
-
Put all the files in the staging area
#Put everything in the folder in the staging area $ git add --all #Git add --all is an easy way to write it $ git add . Copy the code
- Use either of the above instructions when storing all of them
-
Pull content that has been placed in the staging area back into the workspace
#Pull back the index.txt file from the staging area $ git reset HEAD -- index.txt #Pull back to the ceshi folder in the staging area $ git reset HEAD -- ceshi/ #Pull back all files from the staging area $ git reset HEAD -- . Copy the code
- Note: — there are Spaces on both sides, one when you pull back all files.
-
Temporary storage area, just to help us temporarily store content, we delete or will lose
-
To help us save it, we also need to put the contents of the staging area into the history area
GIT historic district
-
Git history is a way of turning files in our staging area into historical versions
-
When some files form a version, they are recorded all the time
-
When adding content to the history area, you must ensure that the temporary storage area has content
-
Because a history zone is a collection of the contents of a temporary storage area
-
Git commit -m “Make a brief note”
#Put the contents of the staging area into the history area $ git commit -m "I'm the first version." Copy the code
- We must write a simple explanation
- Because when we have more versions of history, we can’t remember which version made which changes
- So it would be nice to have a simple explanation
-
That’s when we had our first version of the History zone
-
We use git log to check the version information
#View the version information about the current historical zone $ git log Copy the code
-
Commit: indicates the version number of this version
-
Author: the Author
-
Date: indicates the record time of the current version
-
What follows is the note I wrote when I submitted it
-
Next we make some changes to the contents of the folder and create a historical version again
-
Modify the text content in index. TXT
- from
hello world
Change intoHello world
- from
-
Then we print the log again and look at it
-
We found that the log messages became two, so we had two versions of the content
-
In the historic district, you can’t lose it in theory
-
Now we can delete the content in our local workspace, and after deleting it we can go back to history
-
We use git reset –hard version number for history rollback
#Fall back to the first committed version $ git reset --hard ce0c17f7a703c6847552c7aaab6becea6f0197f2 #Fall back to the second committed version $ git reset --hard abb2c4f12566440e04bc166c3285f855a37a3bb2 Copy the code
-
At this point we can go back and forth and play with our history records