[Full stack plan - Git of development tools] Chapter 1 - Git first experience and version control

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.
insert image description here
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 ]
insert image description here

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.

insert image description here

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.

insert image description here
But from my own point of view:为协作开发而生。


insert image description here

① 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.

insert image description here

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

insert image description here

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.
insert image description here

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
insert image description here


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.
insert image description here

After the installation is complete, find it in the start menu, Git->Git Bashand something similar to the command line window pops up, which means that the Git installation is successful!
insert image description here

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 configto 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 homebrewinstall Gitit, please refer to the documentation of homebrew for the specific method

AppStoreMethod 2 (recommended): Install directly from XcodeGit Xcode.
insert image description here

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 Toolsit, and click Installto 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 gityou 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 installthese 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:
insert image description here
工作区可以理解为是自己计算机本地的创建的一个文件夹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后的本地文件,版本库存放新一个版本状态的提交文件。

insert image description here

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

insert image description here

Expansion:
Here you can also accumulate an operation about creating a folder with Linux instructions

mkdir GitDemo

insert image description here
enter this folder

cd gitDemo

insert image description here

① 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.
insert image description here
I now manually create a file demo.txt, and compile certain content in it for subsequent demonstrations.
insert image description here

② 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.
insert image description here

③ Temporarily store git add

git add

insert image description here
Let's look at the status again and see if there are any prompts,
insert image description here
then submit it honestly.

The command to submit git commit is like this

git commit -m"本次提交想要备注的内容,可以使用英语,也可以使用中文"

insert image description here
If you don't write -m"需要备注的内容"it, you will enter the Vim editing window that most people are not familiar with.
insert image description here
You can refer to this blogger's blog for
Git Vim editor input, save and exit operations

Edit mode:
insert image description here
Command mode:
insert image description here
Type :wq to save and leave, then press Enter to save and exit.
insert image description here

⑤ View the log git log

git log

insert image description here
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

insert image description here

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.
insert image description here
② Then re-add and commit
insert image description here
to complete the commit
insert image description here
expansion: When there are too many logs to be viewed, this interface that cannot be entered will appear.可以键入q解决
insert image description here

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
insert image description here


insert image description here

insert image description here

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.
insert image description here
Now I will manually update the content of both versions. then used for demonstration

Expansion: If you find git addit git commit -ma little troublesome to use and frequently, you can consider using the merge method.

insert image description here

Submit the updated version to the Git repository for management

insert image description here

Demogit reset --hard HEAD^
insert image description here

Demogit reset --hard HEAD^^
insert image description here


Here is a small detail, let's compare the two version control codes and check the results of the log:
use git reset --hard HEADwill modify the commit information ,
use git reset --hard 具体版本号will not modify the commit information

insert image description here
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.
insert image description here

Summarize

初始化,查看状态,暂存,提交和查看日志The five operations, which are the foundation of the foundation, must be mastered.

Guess you like

Origin blog.csdn.net/weixin_52621323/article/details/125699659