Article directory
Preface - the collision of open source ideas, Git, and personal Demo
I have indeed entered this summer vacation that the author himself is very unwilling to face. But since it comes, you can rest assured. Make full use of this summer vacation to polish yourself. Therefore, I have launched a 全栈计划
column to record the efforts made to improve myself and to get the offer. At the same time, this column will also become a very detailed system. teaching column.
Concentrate a little bit, reach the top, beat myself into a sharp blade, I don't want to change back to the self who can't do anything anymore.
One: My holiday project is mainly to use Unity to develop games and embedded two aspects, both of which are used to cope with the competition. There shouldn't be a very systematic study outline. I will go back and learn whatever technology I need. For example, I'm now looking back at making up Git's operations.
The second: after listening to CSDN senior Wang Lumin discussing open source [ live playback ], and that he is indeed participating in Wang's open source plan. I'll keep thinking about it myself.
[ Documentation about open source ]
So in any case, this Git is set to learn and use.
The series of articles [Full Stack Project - Git of Development Tools] is almost finished, and there is still one more to access GitHub.
However, it is still an entry-level or intermediate operation. With the deepening of my study, the projects I have participated in or initiated by myself increase, and I will definitely improve the project content of advanced Git operations.
If you are willing to let Yang Zhi accompany everyone to make progress, you can subscribe to the column first, because it will be a paid column later.
Knowledge of Git & GitHub
Regarding the role of Git, I think the introduction to Git that monkeys can understand is quite vivid and cute in the introduction.
But from my own point of view:为协作开发而生。
① Git is a free and open source
分布式版本控制系统
, because it records the changes of a file or a group of files over time so that a specific version can be called later, so精准的控制更改过的每一个版本
yes, it is the most mainstream distributed version control system at present.
② This distributed version control system can help users to distinguish between保存所有的修改记录
uses版本号
and use the version number to accurately control each version that has been modified.
③ With this kind of system, we can browse historical versions at any time, restore the error-corrected files to the specified version, and compare the differences between files of different versions, which has the function of recovery and protection.
GitHub is the mainstream,
代码托管平台
and it is not an exaggeration to understand it as a network disk for storing and managing code.
It supports us to upload our own project code to this code hosting platform, and we can also download the code from this platform for our own local use.
Git is an (open source) tool, and GitHub is a platform on which to run Git.
Can't help but remind me of Unity and UnityHub
Git basics
Installation of Git
Tips:
The Git operations in this article and subsequent articles mainly use the Git Bash window after downloading itself to operate through code.
If you think this is not very friendly, you can use the graphical interface of TortoiseGit to achieve the operation.
Follow the "Introduction to Git that Monkeys Can Understand" to get familiar with some Git processes.
Getting started with Git that monkeys can understand
Git was first developed on Linux, and for a long time, Git could only run on Linux and Unix systems. However, slowly someone ported it to Windows. Git now runs on Linux, Unix, Mac, and Windows.
To use Git, the first step, of course, is to install Git. Read the text below depending on the platform you are currently using:
①Install Git on Windows To use Git on Windows, you can download the installer
directly from the Git official website , and then install it according to the default options.
After the installation is complete, find it in the start menu, Git->Git Bash
and something similar to the command line window pops up, which means that the Git installation is successful!
After the installation is complete, you need to set the last step, enter at the command line:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Because Git is a distributed version control system, every machine that uses it must report its name: your name and email address.
Pay attention
git config
to the parameters of the command--global
. Using this parameter means that all Git repositories on your machine will use this configuration. Of course, you can also specify different usernames and email addresses for a certain repository.
② Install Git on Mac
If you are using Mac for development, there are two ways to install Git.
Method 1: Install homebrew
, and then homebrew
install Git
it, please refer to the documentation of homebrew for the specific method
AppStore
Method 2 (recommended): Install directly from Xcode
Git Xcode
.
However, it is not installed by default. You need to run it Xcode
, select the menu Xcode->Preferences
, find it in the pop-up window Downloads
, select Command Line Tools
it, and click Install
to complete the installation.
③ Install Git on Linux
First, you can try typing git to see if Git is installed on the system:
$ git
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
Linux will be very friendly to report whether Git is installed, and will tell you how to install Git.
If you happen to use Debian or Ubuntu Linux, sudo apt-get install git
you can install Git directly in one step, very easy.
If it is other Linux versions, you can install it directly from the source code. First download the source code from the Git official website, then decompress it, and enter: ./config
, make
, sudo make install
these commands are installed.
You can also refer to the installation method Git installation written in the official documentation - (need to translate)
Git workspace, staging area, repository
The relationship between them is roughly as follows:
工作区可以理解为是自己计算机本地的创建的一个文件夹
La.
As for the temporary storage area and the version library, I think it can be understood literally for the time being, and there is no need to accurately interpret the meaning, because it is not helpful for us to write code:
暂存区暂存add后的本地文件,版本库存放新一个版本状态的提交文件。
Nine basic operations of Git
Just follow my operation and you will be pretty clear about the basic operation of Git.
The first five basic operations
Expansion:
Here you can also accumulate an operation about creating a folder with Linux instructions
mkdir GitDemo
enter this folder
cd gitDemo
① Initialization operation - git init
git init
This action will create a new subdirectory under this folder called .git containing all the necessary repository files - a Git存储库骨架
. This is the basis for Git to be able to operate on that folder.
I now manually create a file demo.txt, and compile certain content in it for subsequent demonstrations.
② View status git status
git status
Learning to check the status is actually quite important, because the prompts displayed by Git through the window can guide us well in subsequent operations.
③ Temporarily store git add
git add
Let's look at the status again and see if there are any prompts,
then submit it honestly.
④
The command to submit git commit is like this
git commit -m"本次提交想要备注的内容,可以使用英语,也可以使用中文"
If you don't write -m"需要备注的内容"
it, you will enter the Vim editing window that most people are not familiar with.
You can refer to this blogger's blog for
Git Vim editor input, save and exit operations
Edit mode:
Command mode:
Type :wq to save and leave, then press Enter to save and exit.
⑤ View the log git log
git log
If you just want to use the version number (that long hash value) to lock to a specific version, you can use
git log --pretty=oneline
expand:
Use the above five basic operations to achieve version control
① First, we simulate the development process, pretending that the new project version is iterated now.
② Then re-add and commit
to complete the commit
expansion: When there are too many logs to be viewed, this interface that cannot be entered will appear.可以键入q解决
It is still simulated development. At this time, it is found that the newly updated version is not easy to use. I want to roll back to the first-generation version. At this time, I want to roll back to the previous version, or to a specified version.
Method one instruction:
git reset --hard 版本号
The version number can be viewed through andgit log
, and then the desired version version number can be obtained to achieve version control . This is the feedback obtained in Git Bash. The feedback actually returns to the demo.txt file. It can be found that the file has indeed been modified and returned to what you want To your version Method two instructions:git reflog
git reset --hard HEAD^ 线性回退几次,就打几个^
Method two requires understanding one HEAD指针
.
The latest version number of the current branch pointed to by the HEAD head pointer.
The specific implementation can be explained by this picture.
Now I will manually update the content of both versions. then used for demonstration
Expansion: If you find git add
it git commit -m
a little troublesome to use and frequently, you can consider using the merge method.
Submit the updated version to the Git repository for management
【Demogit reset --hard HEAD^
】
【Demogit reset --hard HEAD^^
】
Here is a small detail, let's compare the two version control codes and check the results of the log:
use git reset --hard HEAD
will modify the commit information ,
use git reset --hard 具体版本号
will not modify the commit information
The operation so far is to effectively control the various versions of the project in combination with Git. The remaining four operations, such as cloning, pulling, pulling and merging, and pushing, need to be demonstrated in combination with GitHub or Gitee, which will be more vivid. Let's start with a preliminary understanding of this code hosting platform in the next article.
Summarize
初始化,查看状态,暂存,提交和查看日志
The five operations, which are the foundation of the foundation, must be mastered.