


In Linux, the command to install git is "yum install git"; yum is the abbreviation of "Yellow dog Updater Modified". yum is used to automatically upgrade, install, remove rpm packages, and collect rpm packages. Related information, checks dependencies and automatically prompts users to resolve, so yum can be used to install git.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is the command to install git on Linux
Git official website
https://git-scm.com/
Install Git
[root@git ~]# yum install git #git的安装,直接使用yum安装
View version
[root@git ~]# git --version #查看git的版本git version 1.8.3.1
Expand knowledge:
git personal identity setting
Git is a distributed version control system, so every developer should install Git on his or her laptop and then set his or her personal identity information on git.
[root@git ~]# git config --global user.name "lisi" #设置用户姓名[root@git ~]# git config --global user.emain "456789123@qq.com" #设置邮箱[root@git ~]# git config --global color.ui true #enable ui颜色[root@git ~]# git config --list #查看配置user.name=lisi user.emain=456789123@qq.com color.ui=true[root@git ~]#
The three core frameworks of Git
Working Directory: It is the directory where developers usually store project code;
Staging area (Stage ): Used to temporarily store changes to developer code. In fact, it is just a file that saves the file list information to be submitted;
Git warehouse (Repository): It is a safe place to store data. The git warehouse has submitted by developers. Data codes for all versions, where HEAD points to the latest version put into the warehouse.
The workflow of Git is generally:
1. Add and modify code files in the working directory;
2. Put the code files that need version management into the temporary storage area;
3. Submit the files in the temporary storage area to the Git warehouse.
Therefore, files managed by Git have three states: modified, staged and committed, which correspond to each of the above processes in turn.
git command practice
1. Create and initialize a project directory, and store the editing code in this directory;
[root@git ~]# mkdir Dosier_Project #创建一个项目代码目录 [root@git ~]# cd Dosier_Project/ #进入目录 [root@git Dosier_Project]# git init #初始化目录,让目录受到git版本控制 Initialized empty Git repository in /root/Dosier_Project/.git/ #初始化了一个空的git仓库 [root@git Dosier_Project]# ll -al #查看该目录 total 0 drwxr-xr-x 3 root root 18 Jan 31 16:15 . dr-xr-x---. 5 root root 215 Jan 31 16:14 .. drwxr-xr-x 7 root root 119 Jan 31 16:15 .git #发现git init初始化命令就是生成了.git目录,这个.git目录就是git仓库,以后在Dosier_Project目录下做的所有操作就可以受到git版本控制了 [root@git Dosier_Project]#
2. Simulate development engineers to develop code files
[root@git Dosier_Project]# cd /root/Dosier_Project/ #进去到项目目录 [root@git Dosier_Project]# vim dossier.sh #创建一个代码文件 [root@git Dosier_Project]#
3. git add submits the code files to the temporary storage area
[root@git Dosier_Project]# git status #查看状态 # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # dossier.sh nothing added to commit but untracked files present (use "git add" to track) #解释:Untracked files 说明存在未跟踪的文件(下边红色的那个) #所谓的“未跟踪”文件,是指那些新添加的并且未被加入到暂存区域或提交的文件。它们处于一个逍遥法外的状态,当你一旦将它们加入暂存区域或提交到 Git 仓库,它们就开始受到 Git 的“跟踪”了 [root@git Dosier_Project]# git add dossier.sh #用git add命令把文件提交暂存区 [root@git Dosier_Project]# git status #再次查看状态 # On branch master # # Initial commit # # Changes to be committed: #意思是要提交的更改,等待提交 # (use "git rm --cached <file>..." to unstage) # # new file: dossier.sh #暂存区已经有一个文件了 # [root@git Dosier_Project]#</file></file>
4. git commit submits all the files in the temporary storage area to the git warehouse
git commit is to transfer the temporary storage area Submitting all files to the git repository does not mean submitting a certain file.
[root@git Dosier_Project]# git commit -m "lisi add dossier.sh file" #提交暂存区内的文件到git仓库,-m参数表示写的注释 [master (root-commit) c2b3806] lisi add dossier.sh file 1 file changed, 2 insertions(+) create mode 100644 dossier.sh [root@git Dosier_Project]# git status #再次查看状态,提示暂存区没有要commit的,工作目录文件也没有编辑过 # On branch master nothing to commit, working directory clean [root@git Dosier_Project]#
5. Continue to simulate version 2 and version 3
#模拟版本2,模拟版本2为修改dossier_1.sh文件,新加一个dossier_2.sh文件 [root@git ~]# cd ~/Dosier_Project/ [root@git Dosier_Project]# echo "I am good dossier_1" >> dossier_1.sh #修改了dossier_1.sh文件 [root@git Dosier_Project]# touch dossier_2.sh #新加dossier_2.sh文件 [root@git Dosier_Project]# echo "I am dossier_2" >> dossier_2.sh [root@git Dosier_Project]# git add * #星号匹配所有(等价于--all),把所有文件提交暂存区 [root@git Dosier_Project]# git commit -m "modified dossier_1.sh,add dossier_2.sh" #git commit提交暂存区文件到仓库 [master beff2ea] modified dossier_1.sh,add dossier_2.sh 2 files changed, 2 insertions(+) create mode 100644 dossier_2.sh [root@git Dosier_Project]# git status #查看状态,三大区域已经一致 # On branch master nothing to commit, working directory clean #继续模拟版本3,继续模拟版本3为新加一个dossier_3.sh文件 [root@git Dosier_Project]# touch dossier_3.sh #新加一个dossier_3.sh文件 [root@git Dosier_Project]# echo "I am dossier_3">> dossier_3.sh [root@git Dosier_Project]# git add dossier_3.sh #把dossier_3.sh提交到暂存区 [root@git Dosier_Project]# git commit -m "Add dossier_3.sh" #把暂存区内容提交到git仓库 [master 72cd563] Add dossier_3.sh 1 file changed, 1 insertion(+) create mode 100644 dossier_3.sh [root@git Dosier_Project]# git status #查看状态,三大区域已经一致 # On branch master nothing to commit, working directory clean [root@git Dosier_Project]# 以上,我们就创建了3个版本,版本1为创建dossier_1.sh文件,版本2为修改dossier_1.sh文件,新加一个dossier_2.sh文件,模拟版本3为新加一个dossier_3.sh文件 #查看状态,三大区域已经一致# On branch masternothing to commit, working directory clean[root@git Dosier_Project]# 以上,我们就创建了3个版本,版本1为创建dossier_1.sh文件,版本2为修改dossier_1.sh文件,新加一个dossier_2.sh文件,模拟版本3为新加一个dossier_3.sh文件
6. Use git log command and git reflog command to check which versions are in the git warehouse
Both git log and git reflog commands can be used Check which versions are in the git warehouse, but the difference between the two is that git log can only see the current version, while git reflog can see all versions. That is to say, when you roll back the version, git reflog can see the response. To return to the previous version, you can generally use git reflog.
[root@git Dosier_Project]# git log #git log命令查看git仓库中有哪些版本commit 72cd563e2e0241670d7ebe8c541f28a12875e1e8 Author: lisi Date: Mon Jan 31 18:05:42 2022 +0800 Add dossier_3.sh commit beff2eaf816f345ba39779494752228a06ac1499 Author: lisi Date: Mon Jan 31 18:01:03 2022 +0800 modified dossier_1.sh,add dossier_2.sh commit ae2c1b8752efd01ef265e2227dd0b4ceb81310f4 Author: lisi Date: Mon Jan 31 17:53:32 2022 +0800 Add dossier_1.sh[root@git Dosier_Project]# git reflog #git reflog命令查看git仓库中有哪些版本72cd563 HEAD@{0}: commit: Add dossier_3.sh beff2ea HEAD@{1}: commit: modified dossier_1.sh,add dossier_2.sh ae2c1b8 HEAD@{2}: commit (initial): Add dossier_1.sh[root@git Dosier_Project]#
7. git reset --hard version number to achieve free version rollback
[root@git Dosier_Project]# git reflog #git reflog命令查看git仓库中有哪些版本,前面的字符就是版本号72cd563 HEAD@{0}: commit: Add dossier_3.sh beff2ea HEAD@{1}: commit: modified dossier_1.sh,add dossier_2.sh ae2c1b8 HEAD@{2}: commit (initial): Add dossier_1.sh[root@git Dosier_Project]# git reset --hard beff2ea #回退到版本2,即修改dossier_1.sh文件,新加dossier_2.shHEAD is now at beff2ea modified dossier_1.sh,add dossier_2.sh[root@git Dosier_Project]# ll #查看文件,已经没有了dossier_3.sh文件total 8-rw-r--r-- 1 root root 35 Jan 31 17:56 dossier_1.sh -rw-r--r-- 1 root root 15 Jan 31 17:56 dossier_2.sh[root@git Dosier_Project]# cat dossier_1.sh #dossier_1.sh的最后一行也确实实在版本2时候添加的I am dossier_1 I am good dossier_1[root@git Dosier_Project]# git reset --hard ae2c1b8 #回退到版本1HEAD is now at ae2c1b8 Add dossier_1.sh[root@git Dosier_Project]# lltotal 4-rw-r--r-- 1 root root 15 Jan 31 18:38 dossier_1.sh #已经回退到版本1[root@git Dosier_Project]# cat dossier_1.sh #已经回退到版本1I am dossier_1 [root@git Dosier_Project]#[root@git Dosier_Project]# git reflog #git reflog命令可以看到你所有的版本已经回退版本的记录ae2c1b8 HEAD@{0}: reset: moving to ae2c1b8 beff2ea HEAD@{1}: reset: moving to beff2ea 72cd563 HEAD@{2}: commit: Add dossier_3.sh beff2ea HEAD@{3}: commit: modified dossier_1.sh,add dossier_2.sh ae2c1b8 HEAD@{4}: commit (initial): Add dossier_1.sh[root@git Dosier_Project]# git reset --hard 72cd563 #为了后面实验,现在还是回退到版本3吧HEAD is now at 72cd563 Add dossier_3.sh[root@git Dosier_Project]# ll #已经回退到版本3了total 12-rw-r--r-- 1 root root 35 Jan 31 18:44 dossier_1.sh -rw-r--r-- 1 root root 15 Jan 31 18:44 dossier_2.sh -rw-r--r-- 1 root root 15 Jan 31 18:44 dossier_3.sh[root@git Dosier_Project]#
8. git checkout – filename, undo file modification (the file is not submitted to the temporary storage area)
The development engineer has modified a certain file, but the file has not been submitted to the temporary storage area. The modification of the file needs to be undone. The initial state of the file can be restored by deleting the file content. However, if a lot of modifications have been made, you may not even know what to delete. content, you can use the git checkout command at this time:
[root@git Dosier_Project]# echo "testesshfkshdsjdhjshka" >> dossier_3.sh [root@git Dosier_Project]# cat dossier_3.shI am dossier_3 testesshfkshdsjdhjshka[root@git Dosier_Project]# git checkout -- dossier_3.sh #撤销文件修改,注意命令--后面是空格接文件名[root@git Dosier_Project]# cat dossier_3.sh #已经撤销成功I am dossier_3[root@git Dosier_Project]#
9. git reset HEAD file, undo the file in the temporary storage area
[root@git Dosier_Project]# echo "boss is good ">>dossier_3.sh #编辑一点内容[root@git Dosier_Project]# git add dossier_3.sh #提交暂存区,这时突然反悔了,需要从暂存区撤销该文件[root@git Dosier_Project]# git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage) #这里已经提示了,撤销暂存区文件使用git reset HEAD## modified: dossier_3.sh#[root@git Dosier_Project]# git reset HEAD dossier_3.sh #撤销暂存区内的指定文件Unstaged changes after reset: M dossier_3.sh[root@git Dosier_Project]#</file>
10. Delete a file and submit it to the temporary storage with git rm District
[root@git Dosier_Project]# rm -rf dossier_1.sh #当文件不需要了直接rm -rf删除一个文件[root@git Dosier_Project]# git status #查看状态# On branch master# Changes not staged for commit:# (use "git add/rm <file>..." to update what will be committed) #这里其实已经提示你使用add或rm参数了# (use "git checkout -- <file>..." to discard changes in working directory)## deleted: dossier_1.sh#no changes added to commit (use "git add" and/or "git commit -a")[root@git Dosier_Project]# git rm dossier_1.sh #提交暂存区[root@git Dosier_Project]# git commit -m "delete dossier_1.sh" #把暂存区内容commit提交git仓库</file></file>
Recommended learning: Linux video tutorial
The above is the detailed content of What is the command to install git on linux. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
