# Git工程实践

<font style="background:yellow">
1

# 目录

[TOC]

Github、GitLab、Gitee、Git的区别?

  • Git是版本管理软件【核心是软件】
  • Github、GitLab、Gitee都是在线代码托管的仓库【核心是网站】
    • 我们常说有个网站叫【https://gitlab.cn/】,这个是面向全部互联网用户的
    • 但我们自己可以借助gitlab网站本身的源代码自己搭建一个属于自己个人或者公司的【私有服务】自己公司的gitlab,这个就我们自己可控

# 1.安装Git软件

Windows上,直接官网下载,一路按默认选项安装即可

# 2.”首次“使用Git设置

# 2.1.本地的Git的bash中建立『非对称加密秘钥

1.本地Git bash随便在哪个目录输入下面命令(注意,邮箱要和你GiteeGitHubGitLab上的一致)

ssh-keygen -t rsa -C "[email protected]"
1

然后不论这行命令后问你什么,你一路enter,就能生成秘钥

2.查找秘钥中的公钥:借助everthing软件查找.ssh

  • 其实,这个公钥叫作id_rsa.pub,重点在.pub浅显易懂,而另一个是私钥,是本地用
  • 如果熟悉window目录结构的,可以直接去“系统盘”目录下的users中找.ssh文件,在那个里面

3.将该公钥放在GiteeGitHub,这样,你上传代码到仓库就能有安全性能保证+才能上传到仓库,不然不准上传到仓库!

# 本地再弄一个ssh/一台电脑连接管理多个git账号

whoway@LAPTOP-DI85I9OS MINGW64 ~/Desktop/SQL-note (main)
$ ssh-agent.exe bash

whoway@LAPTOP-DI85I9OS MINGW64 ~/Desktop/SQL-note (main)
$ ssh-add.exe
.git/        README.md    SQL-note.md

whoway@LAPTOP-DI85I9OS MINGW64 ~/Desktop/SQL-note (main)
$ ssh-add.exe ~/.ssh/
config                 id_rsa.pub             id_rsa_sylv.pub
id_rsa                 id_rsa_sylv      known_hosts

whoway@LAPTOP-DI85I9OS MINGW64 ~/Desktop/SQL-note (main)
$ ssh-add.exe ~/.ssh/id_rsa_sylv
Identity added: /c/Users/whoway/.ssh/id_rsa_sylv (/c/Users/whoway/.ssh/id_rsa_sylv)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • ==原因==:因为Git==默认使用id_rsa==

2.2.远程Gitee/GitHub绑定邮箱

  • 自行绑定邮箱,因为这样,才能用这个邮箱,识别哪个Git上传的,贡献度,他们会计算

2.3.在本地绑定邮箱和远程的Gitee/Github的用户名

  • 方式1:指定本机器的全局git名称+邮箱, 安装完成后,还需要最后一步设置,在命令行输入:
$ git config --global user.name "你的用户名"
$ git config --global user.email "你的邮箱-格式如后[email protected]"
1
2

方式2:某仓库使用局部名字+邮箱指定

可以对某个仓库指定不同的用户名和Email地址。

C:\Users\MaxWell>git config user.name whoway
C:\Users\MaxWell>git config user.email [email protected]
1
2

验证效果-查询当前仓库,你用的身份是咋样?

  • Git是分布式版本控制系统,所以每个机器都必须自报家门:你的名字和Email地址。「注意git config命令的--global参数」 表示你这台机器上所有的Git仓库都会使用这个配置,设置后,如果你想,查看git全局用户名和邮箱「注意,这个也会看到局部的git仓库的局部名称+邮箱」 比如:
C:\Users\MaxWell>git config user.name
whoway
C:\Users\MaxWell>git config user.email
[email protected]
1
2
3
4

# Git的细节

1、Git的下载的.git用途

  • 注意:git clone下来的文件,顺路会把.git也下载下来,所以,我们才能提交,这个文件,是用作版本记载的

2、Git中httpsSSH的clone方式区别⭐️ 在git中clone项目有两种方式:HTTPS和SSH,它们的区别如下:

  • HTTPS:不管是谁【因为https单纯就是服务器】,拿到url随便clone,但是每次在push的时候需要验证用户名和密码
  • SSH(我经常用这个):clone的项目你必须拥有者或者管理员,而且需要在clone前添加SSH Key到「github/gitee/gitlab啥的」。SSH 在push的时候,是不需要输入用户名+密码的,因为git自行验证ssh key(私钥)
    • 使用的是加密算法验证

3、我在windows电脑上发现:Git中为啥能使用部分linux命令?

  • Git中封装了小型的bash,比如我们发现,它里面还能用sshvim这些啥的。 比如git for Windows 自带了个 mingw 啊。git 要正常运行需要这个最小的 mingw 环境。

# 常用场景

【1】Git同时关联github和gitee

1.创建新版本库,进行开源

2.初始化一个Git的版本控制咯

git init
touch README.md
1
2

3.提交到本地分支上

git add README.md
git commit -m "first commit:smile:"
1
2

4.绑定远程版本库(本场景的核心解决方案)remote add

重要可以修改的地方,同时用来更新github和gitee

git remote add origin⭐️ [email protected]:HACV/dos.git
1

注意,可以不叫origin那样的名字。比如,我们为了同时绑定GitHub和Gitee,我们使用下面的

git remote add mygitee⭐️ [email protected]:HACV/dos.git
1

【2】git remote -v⭐️查看本地分支和哪个远程分支绑定

//命令1
whoway@test MINGW64 /d/___MyGitbook/Windows (master)
$ git remote -v
mygitee [email protected]:HACV/dos.git (fetch)
mygitee [email protected]:HACV/dos.git (push)
1
2
3
4
5

【3】git remote rm [branchname](取消关联某仓库+去关联其他仓库)

  • 命令rm,一看就和linux下的命令差不多
//取消关联某仓库
MaxWell@mylatop MINGW64 /d/___MyGitbook/DOS/_book (master)
$ git remote rm mygitee


MaxWell@mylatop MINGW64 /d/___MyGitbook/DOS/_book (master)
$ git remote -v


//添加新的关联某仓库=================new=========================
MaxWell@mylatop MINGW64 /d/___MyGitbook/DOS/_book (master)
$ git remote add mygitee [email protected]:HACV/demo.git


MaxWell@mylatop MINGW64 /d/___MyGitbook/DOS/_book (master)
$ git push -u mygitee master
Counting objects: 150, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (140/140), done.
Writing objects: 100% (150/150), 3.68 MiB | 3.56 MiB/s, done.
Total 150 (delta 29), reused 0 (delta 0)
remote: Resolving deltas: 100% (29/29), done.
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:HACV/demo.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'mygitee'.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

【4】git addgit commit的对比⭐️「工作区+版本库」

本地状态图

  • 工作区
  • 版本库
    • stage对应--staged
      • stage
    • HEAD本地仓库

git3

  • Question: add和commit的区别,是不是多次一举?
  • 不是的!
  • 使用 git add命令将想要快照的内容写入缓存区【其实就是把修改登记到.git文件夹下】
  • 使用 git commit命令则将缓存区内容添加到**本地仓库(这里说的本地仓库)**中【意思模拟远程的那种,这个是在.git文件夹下登记一个commit信息】

然后,我们最后git push将本地的那个commit提交到远程仓库

$ git status
On branch master
nothing to commit, working tree clean

MaxWell@DESKTOP MINGW64 /C/Users/MaxWell/Desktop/learn (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  • 我这个时候,没有将它add到staged中去,更加不可能commit
  • git diff看看具体修改了什么内容
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index e69de29..9551247 100644
--- a/readme.txt
+++ b/readme.txt
@@ -0,0 +1 @@
+2123
\ No newline at end of file
1
2
3
4
5
6
7
8
  • 知道了对readme.txt作了什么修改后,再把它提交到仓库就放心多了,提交修改和提交新文件是一样的两步
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   readme.txt
1
2
3
4
5
6

工作目录是干净(working tree clean)

# 3.5.git diff HEAD -- 文件名查看「工作区」和「版本库」里面最新版本的区别⭐️

  • 比如想看README.md的区别
  • git diff HEAD -- README.md命令可以查看工作区和版本库里面最新版本的区别
MaxWell@DESKTOP MINGW64 ~/Desktop/ttt (master)
$ git diff HEAD -- README.md
diff --git a/README.md b/README.md
index 088d087..72b8ba5 100644
--- a/README.md
+++ b/README.md
@@ -30,10 +30,3 @@ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN


-3.  你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了
-4.  [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的
1
2
3
4
5
6
7
8
9
10
11

# 3.6.需远程拉下来新提交⭐️

  • git fetch & pull详解
  • 本地文件丢失了/有人提交了更新

git fetch是将远程主机的最新内容拉到本地,用户在检查了以后决定是否合并到工作本机分支中「深刻理解这个,需要看下面的git status和git branch -a的表现」。

➜  algo git:(main) gst
On branch main
⭐️Your branch is up to date with 'origin/main'.⭐️

⭐️nothing to commit⭐️, working tree clean
➜  algo git:(main) git fetch
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 24 (delta 7), reused 15 (delta 5), pack-reused 0
Unpacking objects: 100% (24/24), 5.39 KiB | 367.00 KiB/s, done.
From github.com:whoway/algo
   1944fe0..af67313  main            -> origin/main
 * [new branch]⭐️      ps_classic_algo -> origin/ps_classic_algo
➜  algo git:(main) git diff
➜  algo git:(main) git branch -a
  macos
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/macos
  remotes/origin/main
  remotes/origin/ps_classic_algo
  remotes/origin/test
  remotes/origin/策略
➜  algo git:(main) git log
➜  algo git:(main) gst
On branch main
⭐️Your branch is behind 'origin/main' by 10 commits, and can be fast-forwarded.⭐️
  (use "git pull" to update your local branch)

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

git pull 则是将远程主机的最新内容拉下来后直接合并

➜  algo git:(main) git pull
Updating 1944fe0..af67313
Fast-forward
 backtrack/backtrack_template.java   | 12 ++++++++++++
 classic_algo/QuickSort.java         | 37 +++++++++++++++++++++++++++++++++++++
 classic_algo/QuickSortOptimize.java | 43 +++++++++++++++++++++++++++++++++++++++++++
 test.md                             |  1 -
 4 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 backtrack/backtrack_template.java
 create mode 100644 classic_algo/QuickSort.java
 create mode 100644 classic_algo/QuickSortOptimize.java
 delete mode 100644 test.md
➜  algo git:(main) gst
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

即:git pull = git fetch + git merge,这样可能会产生冲突,需要手动解决

举例如下,其实git fetch的正确打开方式是这样

  • 「⭐️本地新建一个临时分支,并将远程origin仓库的master分支代码下载到本地临时分支⭐️」

  • 然后再和本地的master比较

[master] git fetch origin master:tmp 
//在本地新建一个temp分支,并将远程origin仓库的master分支代码下载到本地temp分支

[master]  git diff tmp 
//来比较本地代码与刚刚从远程下载下来的代码的区别

[master] git merge tmp
//合并temp分支到本地的master分支

[master] git branch -d temp
//如果不想保留temp分支 可以用这步删除
1
2
3
4
5
6
7
8
9
10
11

# 3.7.git想查看分支是什么时候创建的,直接执行

git reflog show --date=iso 分支名
⭐️
//比如想查看⭐️dev分支⭐️是什么时候创建的
git reflog show --date=iso dev
1
2
3
4

# 4.分支管理(难点)

# 【增】分支,为后续上传github做准备

新建分支,会自动跳转的

新建分支并跳转到分支
git checkout -b 分支名
比如
MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git checkout -b English
Switched to a new branch 'English'

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ ll
total 4
drwxr-xr-x 1 MaxWell 197121  0 52 08:53 China/
-rw-r--r-- 1 MaxWell 197121 30 52 08:53 README.md
1
2
3
4
5
6
7
8
9
10
11
12

# 『注意⭐️分支之后,记得要及时git pull

  • 不然,2个分支都一样。
MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ git add .

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ git commit -m "提交分支"
[English cf8ac23] 提交分支
 2 files changed, 2 insertions(+), 53 deletions(-)
 delete mode 100644 "China/\346\240\274\345\274\217\350\246\201\346\261\202.md"

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ git push origin English
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
remote: Create a pull request for 'English' on Gitee by visiting:
remote:     https://gitee.com/HACV/test/pull/new/HACV:English...HACV:master
To gitee.com:HACV/test.git
 * [new branch]      English -> English

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ ll
total 1
-rw-r--r-- 1 MaxWell 197121 306 52 08:58 README.md

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git pull
Already up to date.

    
MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ ll
total 1
drwxr-xr-x 1 MaxWell 197121  0 52 09:00 China/
-rw-r--r-- 1 MaxWell 197121 30 52 09:00 README.md

MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git checkout English
Switched to branch 'English'

MaxWell@mylatop MINGW64 ~/Desktop/test (English)
$ ll
total 1
-rw-r--r-- 1 MaxWell 197121 306 52 09:01 README.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

# 【删】分支

删的话就比较麻烦了,因为涉及到删除本地和删除远程分支

# 【删远程】某分支?

参考文档 (opens new window)

此外,我观察到,这样删除分支,我们发现commit并没有变化。

  • 当一个分支被推送并合并到远程分支后,-d 才会本地删除该分支。

  • 如果一个分支还没有被推送或者合并,那么可以使用-D强制删除它。

  • 使用这个命令可以远程删除分支:git push <remote> --delete <branch>

  • 你也可以使用这行简短的命令来远程删除分支:git push <remote> :<branch>,比如:git push origin :fix/authentication

  • 使用以下命令同步分支列表:

  • -p 的意思是“精简”。这样,你的分支列表里就不会显示已远程被删除的分支了。

    git fetch -p
    
    1
MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git branch -d English
error: The branch 'English' is not fully merged.
If you are sure you want to delete it, run 'git branch -D English'.

MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git branch -D English
Deleted branch English (was 6b8830c).

MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git branch
* master


MaxWell@mylatop MINGW64 ~/Desktop/test (master)
$ git push origin --delete English
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:HACV/test.git
 - [deleted]         English
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 【删本地】分支

合并完成后,就可以放心地删除dev分支了:
$ git branch -d dev
Deleted branch dev (was b17d20e).
1
2
3

# 5.分支合并

  • 在开发的时候,一般不使用git merget 分支名,因为一般在gitlab和gitHUb

# git merge 【branchname】 分支提交失败的情况

$ git branch dev

MaxWell@mylatop MINGW64 /C/Users/MaxWell/Desktop/Temp (main)
$ git branch
  dev
* main

MaxWell@mylatop MINGW64 /C/Users/MaxWell/Desktop/Temp (main)
$ git checkout dev
Switched to branch 'dev'

MaxWell@mylatop MINGW64 /C/Users/MaxWell/Desktop/Temp (dev)
$ git branch
* dev
  main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

等价于一句

$ git checkout -b dev
Switched to a new branch 'dev'
1
2
当前是main分支

git merge dev
1
2
3
合并完成后,就可以放心地删除dev分支了:

$ git branch -d dev
Deleted branch dev (was b17d20e).
1
2
3
4

# 5.版本回退

# 区分hard和soft的回退方式

  • 区别git reset --hard [commit]git reset --soft [commit]版本回退⭐️

神奇的git reset

$ cat readme.txt
2123
2222

Well@mylatop MINGW64 /C/Users/MaxWell/Desktop/learn (master)
$ git reset --hard HEAD^
HEAD is now at 2e4da7b 第2次提交

Well@mylatop MINGW64 /C/Users/MaxWell/Desktop/learn (master)
$ cat readme.txt
2123
1
2
3
4
5
6
7
8
9
10
11
  • 版本前进—回到当前的未来
$ git reset --hard a68dea			//其实这里是不全的,就算不打全也是可以的
HEAD is now at a68dea8 di 3 ci
1
2
git reflog查看命令历史
1

# 4.9.通过git下载github分支

# git下载【指定分支代码】到本地?

  • 任务:下载地址为https://github.com/hemiahwu/vue-basic-playlist.git;分支名为lesson-2
git clone -b 指定分支名字 httpsxxx.git
git clone -b lesson-2 https://github.com/hemiahwu/vue-basic-playlist.git
1
2

# git下载【所有分支】代码到本地【其实默认】

  • 任务:下载地址为https://github.com/hemiahwu/vue-basic-playlist.git的所有分支代码到本地
git clone https://github.com/hemiahwu/vue-basic-playlist.git
1

(目前仓库所有的分支已经到本地了,只不过默认只显示master一个分支,需要你手动git checkout分支才会显现,如切换到指定分支 即可;git checkout lesson-2)

  • git log --graph命令可以看到分支合并图。
合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并。
1

# ⭐️工作场景实践

# 1.开发+代码提交+提交PR

git checkout -b new		#新建分支,并且切换分支
ls
git add modify_file.name
git commit -m "new branch2021"	
git diff master new	#比较一下代码,在提交前记得检测「不要引发上线事故」
git push origin new	#将本地new分支提交到远程Gitee(也就是Origin)

# 后续自行在你的GitHub/GitLab提交你的描述+PR请求
------------------
git checkout master	#切换当前分支为master
1
2
3
4
5
6
7
8
9
10

# 2.提交的分支错误,删除本地的分支和远程的分支

whoway@LAPTOP-OS MINGW64 ~/Desktop/os (master)
$ git branch -d new					#// delete branch locally
error: The branch 'new' is not fully merged.
If you are sure you want to delete it, run 'git branch -D new'.

whoway@LAPTOP-OS MINGW64 ~/Desktop/os (master)
$ git branch -D new
Deleted branch new (was c18a3d2).

whoway@LAPTOP-OS MINGW64 ~/Desktop/os (master)
$ git push origin --delete new					#delete branch remotely
remote: Powered by GITEE.COM [GNK-6.2]
To gitee.com:HACV/os.git
 - [deleted]         new

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 3.代码走查/自行比较分支

  • git diff branch1 branch2 //显示出所有有差异的文件的详细差异(注意,这个表示branch2在1的基础上有啥修改!顺序⭐️
  • git diff branch1 branch2 文件名(带路径) //显示「指定文件」的详细差异
git查看当前分支所属
git branch --v		#查看当前啥分支	等价于	git branch -vv		#查看当前啥分支
git config --list	#查看分支属于谁,用户名+邮箱名

git diff branch1 branch2 --stat   		//显示出所有有差异的文件列表
1
2
3
4
5

# 3.1.git查看(某分支)相较master的改动

Git 查看某次commit的内容

知道commit id的情况下:
1. 获取commit id
	git log 

2. 查看commit内容
	git show commit_id
	git show ctz > modify.patch
	
查看最近n次提交的修改
   git log -p -n
指定n为1则可以查看最近一次修改的内容
1
2
3
4
5
6
7
8
9
10
11
12
13

# 4.公司给了新的分支-拉去

git拉取远程分支并创建本地分支

拉取远程分支并创建本地分支

方法一 使用如下命令

git checkout -b 本地分支名ctz     origin/远程分支名ctz
1

使用该方式会在本地新建分支ctz,并自动切换到该本地分支ctz。采用此种方法建立的本地分支会和远程分支建立映射关系

方式二 使用如下命令:

git fetch origin 远程分支名x:本地分支名x 使用该方式会在本地新建分支x,但是不会自动切换到该本地分支x,需要手动checkout。

采用此种方法建立的本地分支不会和远程分支建立映射关系。

whowoay@XXXX:~/gcc-$ git branch -r
  origin/HEAD -> origin/master
  origin/ctz
  origin/dev-opt
  origin/lhupeephole2
  origin/master
whowoay@XXXX:~/gcc-$ git checkout -b dev-opt orgin/dev-opt
1
2
3
4
5
6
7

# 6.git cherry-pick进行commit的pick

  • cherry,n.樱桃

  • 参考链接:https://blog.csdn.net/u010697394/article/details/60956514

cherry-pick不但可以用在不同分支之间,也可以用在同一个分支上

  • 一个场景吧:比如今天你新增了一个功能,commit1
  • 第二天这个功能又不需要了,你又不情愿的注释掉,甚至删除了代码,commit2.
  • 然后过了几天,产品过来了,来来来,老弟,还是需要加这个功能,这时候你拿出来菜刀,但产品经理这次却不吃那一套,好吧,那就找回来吧。
  • 这时候就可以用cherry-pick,重新找回来了
whoway@dell:~/open_source/gcc-9.1.0$ git log
commit ⭐️f8a7cf⭐️ (HEAD -> ctz, origin/ctz)
Author: whoway <[email protected]>
Date:   Sat Dec 4 11:58:18 2021 +0800

    modify_ctzsi2_ctzdi2_realize

commit 4e24b2 (origin/master, origin/HEAD, master)
Merge: 9eb72b764 32703ac7f
Author: xinxin <[email protected]>
Date:   Sat Nov 6 09:15:20 2021 +0800

    Merge branch 'master' into 'master'
    
    Master
    
    See merge request code-opt/gcc-9.1.0!1


whoway@XXXX:~/open_source/gcc-9.1.0$ git checkout dev-opt 
Switched to branch 'dev-opt'
Your branch is up to date with 'origin/dev-opt'.

whoway@dell:~/open_source/gcc-9.1.0$ git cherry-pick ⭐️f8a7cf⭐️
[dev-opt 1e2600715] modify_ctzsi2_ctzdi2_realize
 Date: Sat Dec 4 11:58:18 2021 +0800
 1 file changed, 22 insertions(+), 2 deletions(-)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# 如果公司外网域名宕掉—git远程仓库地址变更本地如何修改

  • 参考链接:https://blog.csdn.net/asdfsfsdgdfgh/article/details/54981823

  • gcc -D选项 编译时添加宏定义

  • https://blog.csdn.net/y396397735/article/details/53736416?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.fixedcolumn&spm=1001.2101.3001.4242.1

  • git撤销commit 并保存之前的修改

  • https://blog.csdn.net/mentalitys/article/details/81079761

# 生成某次提交的patch

git format-patch -1 58b649
1

# 解决git pull的冲突

  • git pull更新hcc_riscv_gcc以获得更
warning: redirecting to http://xxxxxxxxxxxxxxvip:仓库名
Updating 69f2ed6 
error: Your local changes to the following files would be overwritten by merge:
        opeource/aute.cache/requests
Please commit your changes or stash them before you merge.
Aborting
1
2
3
4
5
6
  • 出现这个问题的原因是其他人修改了xxx.php并提交到版本库中去了,而你本地也修改了xxx.php,这时候你进行git pull操作就好出现冲突了,解决方法,在上面的提示中也说的很明确了。
  • 参照解决方案 (opens new window)

# 3.7.1.保留本地的修改的改法git stash

  • 1)直接commit本地的修改 —一般不用这种方法
  • 2)通过git stash — 通常用这种方法(==我用了这个方案解决==)
  • 通过git stash将工作区恢复到上次提交的内容,同时备份本地所做的修改,之后就可以正常git pull了,git pull完成后,执行git stash pop将之前本地做的修改应用到当前工作区。
git stash

git pull

git stash pop
1
2
3
4
5
  • git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。
  • git stash pop: 从Git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个Stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。
  • git stash list: 显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。
  • git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现,原来stash的哪些节点都消失了
whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git stash
apply    branch   clear    create   drop     list     pop      push     save     show

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git stash list

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git stash push
Saved working directory and index state WIP on first: 194057b Initial commit

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git stash list
stash@{0}: WIP on first: 194057b Initial commit

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git log
commit 194057b65f837e4f5489a109ddf4e1e79ba84338 (HEAD -> first, origin/master, origin/HEAD, master)
Author: whoway <7799986[email protected]>
Date:   Tue Mar 8 11:15:40 2022 +0000

    Initial commit

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git status
On branch first
nothing to commit, working tree clean

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git diff

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git diff master first

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git stash list
stash@{0}: WIP on first: 194057b Initial commit

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git stash clear

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git stash list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# 3.7.2.放弃本地修改 的改法 —这种方法会丢弃本地修改的代码,而且不可找回

git reset --hard

git pull
1
2
3

# git log查看某个文件的修改历史⭐️公司参考前辈的写法

我看到的更好的方法。

  • 1.git log filename

可以看到fileName相关的commit记录「定位某文件的历次更新

  • 2.git log -p filenam

可以显示每次提交的diff,只看某次提交中的某个文件变化,可以直接加上fileName

# ⭐️获得某文件中-某行代码的修改记录git blame

git blame -L 432 demo.c
1

# ⭐️工程命令列表

# 1.git checkout [filename]取消没add的文件

  • 场景:git取消已经修改的文件,但是还没add的文件
  • 注意:git checkout // 放弃所有文件的所有修改
XXX@XXXX:~/work/gcc-7.3.0$ git checkout gcc/config/riscv/peephole.md
Updated 1 path from the index
XXX@XXXX:~/work/gcc-7.3.0$ git diff
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index b4a33f8c0..2ab69699a 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -88,6 +88,10 @@ femit-lli-expand
 Target Report Var(flag_lli_expand) Init (0)
 All 32 bit immediate are valid for l.li instruction.
 
+mandopt
+Target Report Var(AND_OPT) Init(0) Optimization
+Optimize and to shift.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

git撤销对某个文件的修改

  • 1、如果没有被git add到索引区
    • git checkout build.sh 便可撤销对文件build.sh的修改
    • 注意:git checkout // 放弃所有文件的所有修改
  • 2、git 恢复某个文件到指定版本
    • git提交了比较多的文件到远程,但是在合并时发现其中有一个文件合并有冲突或者某个原因不想修改该文件了,那就需要单独把这个文件回退到上一个提交版本状态。方法如下:
    • 1.首先查看一下该文件的commit记录:git log 文件名,例如 git log src/index.java
    • 2.找到需要提交到上一个版本的commit号,然后checkout该文件的上一版本,输入下面的指令:
      • git checkout [commit id] 文件,例如 git checkout a57fb4b474888f0db4cba18de2180496 src/index.java

# 2.git checkout -切换回上一个分支

  • 类似cd -的操作
whoway@XXXX:~/work$ git checkout -
Switched to branch '132shift'
whoway@XXXX:~/work$ ^C
whoway@XXXX:~/work$ git checkout -
Switched to branch 'and2'
whoway@XXXX:~/work$ git checkout -
Switched to branch '132shift'
1
2
3
4
5
6
7

# 3.从「commit到stage」到修改到「取消修改(回退)」git reset --soft

  • git reset --soft 编号
  • git restore --staged 文件名字
    • restore,v.恢复
    • 记忆法:--staged对应的就是staged区域

whoway@XXXX:~/open_source$ git log
commit 720e55e56335975d7729816a542f7f5af0b2d7f1 (HEAD -> lbpeephole2)
Author: whoway <[email protected]>
Date:   Tue Dec 7 17:29:18 2021 +0800

    add_option_mlbu-lhu-opt_lhupeephole2

commit a3f117296f1a6ea77c9f44a343eded7ff79eb5f2 (origin/dev-opt)
Author: xinxinxin <[email protected]>
Date:   Tue Dec 7 16:42:34 2021 +0800

    dev-opt


whoway@XXXX:~/open_source$ git reset --soft a3f117296f1

whoway@XXXX:~/open_source$ git status
On branch lbpeephole2
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   ../../../../config/riscv/peephole.md
        modified:   ../../../../config/riscv/riscv.opt
        modified:   ../../../../../libgcc/libgcc2.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        lbu2lhu16bits.c
        lbu2lhu8bits.c
        ../../../../../libgcc/tempwhoway


whoway@XXXX:~/open_source$ git restore --staged ../../../../../libgcc/libgcc2.c


whoway@XXXX:~/open_source$ git status
On branch lbpeephole2
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   ../../../../config/riscv/peephole.md
        modified:   ../../../../config/riscv/riscv.opt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   ../../../../../libgcc/libgcc2.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        lbu2lhu16bits.c
        lbu2lhu8bits.c
        ../../../../../libgcc/tempwhoway
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

# ⭐️补丁patch相关

# 如何生成Patch?

  • 显然,git diff 和重定向,是可以
  • 其次git format-patch -p -2也可以

# 如何打Patch?⭐️git apply --check XXX.patchgit apply XXX.patchgit am XX.patch

  • 参考资料:https://blog.csdn.net/qq_15936309/article/details/90521360
$ git apply --stat aaaa.patch   # 查看patch的情况
$ git apply --check aaaa.patch   # 检查patch是否能够打上,如果没有任何输出,则说明无冲突,可以打上
$ git apply a.patch  # 打patch


1
2
3
4
5

注:git apply是另外一种打patch的命令

  • 其与git am的区别是,git apply并不会将commit message等打上去,打完patch后需要重新git add和git commit
  • 而git am会直接将patch的所有信息打上去,而且不用重新git add和git commit
  • author也是patch的author而不是打patch的人

# git am XX.patch但是没有check的效果

git format-patch -3 //⭐️⭐️⭐️从当前分支最新提交点往下共生成3个补丁
git format-patch -1 指定commit号 //⭐️⭐️生成指定commit号的补丁
eg:git format-patch -1 5f123e379cc97c317d6094bcfa2281e1189d61f3
生成5f123e379cc97c317d6094bcfa2281e1189d61f3号的补丁,该commit号⭐️⭐️不一定在该分支开头⭐️⭐️,可以在该分支的任意位置。
1
2
3
4
使用 am 命令应用补丁
如果补丁的贡献者也是一个 Git 用户,并且其能熟练使用 format-patch 命令来生成补丁,这样的话你的工作
会变得更加轻松,因为这种补丁中包含了作者信息和提交信息供你参考。 如果可能的话,请鼓励贡献者使用
format-patch 而不是 diff 来为你生成补丁。 而只有对老式的补丁,你才必须使用 git apply 命令。
要应用一个由 format-patch 命令生成的补丁,你应该使用 git am 命令 (该命令的名字 am 表示它“应用
(Apply)一系列来自邮箱(Mailbox)的补丁”)。 从技术的角度看,git am 是为了读取 mbox 文件而构建
的, mbox 是一种用来在单个文本文件中存储一个或多个电子邮件消息的简单纯文本格式。 其大致格式如下所
示:


whoway@XXXXX MINGW64 ~/Desktop/www (first)
$

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git log
commit 48fb0358dea51acc89a28c5a2485e78618e8d4ce (HEAD -> first, origin/first)
Author: HACV <[email protected]>
Date:   Tue Mar 8 19:27:39 2022 +0800

    temp

commit 194057b65f837e4f5489a109ddf4e1e79ba84338 (origin/master, origin/HEAD, master)
Author: whoway <7799986[email protected]>
Date:   Tue Mar 8 11:15:40 2022 +0000

    Initial commit

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git format-patch -1 48fb
0001-temp.patch

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ ls
0001-temp.patch  README.md

whoway@XXXXX MINGW64 ~/Desktop/www (first)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git apply --check 0001-temp.patch

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git a
add        am         annotate   apply      archive    askpass

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git am
.git/            0001-temp.patch  README.en.md     README.md

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git am 0001-temp.patch
Applying: temp

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git log
commit 771339bf5c93a4b8bbab573c54bfe7966fdf878c (HEAD -> master)
Author: HACV <[email protected]>
Date:   Tue Mar 8 19:27:39 2022 +0800

    temp

commit 194057b65f837e4f5489a109ddf4e1e79ba84338 (origin/master, origin/HEAD)
Author: whoway <7799986[email protected]>
Date:   Tue Mar 8 11:15:40 2022 +0000

    Initial commit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

# 附录1-思考

# Git的笔试/面试

是否使用过 git commit 命令
是否使用过 git fetch 命令
是否使用过 git stash 命令
是否使用过 git lfs 命令
1
2
3
4
  • 区分git reabse和git merge

# git的分支怎么理解?

我的理解是,git的分支是个横着摆放多叉树

# 关于.gitignore的编写【有坑】

  • .gitignore忽略它本身:
    • 【注意】我们必须将.gitignore文件和**.git文件夹放在同一个目录**!才能生效!

      • 放在其他目录可能.gitignore还是被追踪!
      • 这是我以前学习的一个错误的地方!现在纠错

我的模版

#不追踪.git  ignore本身
.gitignore
#不追踪Mac电脑自动生成的.DS_Store
.DS_Store
**/.DS_Store
._.DS_Store
**/._.DS_Store
#不追踪idea软件系列
**/.idea
#不追责vscode系列
./.vscode
#不追踪指定文件
fis-conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13

# 关于.git文件夹是干啥的?

# 【省时】-Git设置命令别名

  • git命令设置简写(别名)

linux下:任意路径下输入:vim ~/.gitconfig,在后边追加如下内容

[alias]
    ckt = checkout
    ci = commit
    st = status
    pl = pull
    ps = push
    gdf = gitdiff
    l = log
    cp = cherry-pick
    ca = commit -a
    b = branch
1
2
3
4
5
6
7
8
9
10
11

参考链接:https://mp.weixin.qq.com/s/56bJT2FGZBZuTqde-pf7sg

Git 基础 - Git 别名:https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-Git-%E5%88%AB%E5%90%8D

whoway@dell:~/micro-benchmark-fortran$ cat ~/.gitconfig 
[user]
	email = [email protected]
	name = whoway
[alias]
	st = status
1
2
3
4
5
6

我使用的别名是MacOS M1下自带的别名

gst='git status'
gsh='git show'
gl='git pull'
gd='git diff'

ga='git add'
gcmsg='git commit -m'
gp='git push'
1
2
3
4
5
6
7
8

# 【省时】-可视化git工具-推荐fork

img

  • https://git-fork.com/

# 【有人把git当pdf库?】.git lfs的使用

# Gitee个人版不行

whoway@XXX MINGW64 ~/Desktop/www (master)
$ ls
README.en.md  README.md  temp.pdf

whoway@XXX MINGW64 ~/Desktop/www (master)
$ git lfs track "temp.pdf"
Tracking "temp.pdf"

whoway@XXX MINGW64 ~/Desktop/www (master)
$ git lfs track
Listing tracked patterns
    temp.pdf (.gitattributes)

whoway@XXX MINGW64 ~/Desktop/www (master)
$ ls
README.en.md  README.md  temp.pdf

whoway@XXX MINGW64 ~/Desktop/www (master)
$ cat .^C

whoway@XXX MINGW64 ~/Desktop/www (master)
$ cat .gitattributes
temp.pdf filter=lfs diff=lfs merge=lfs -text
whoway@XXX MINGW64 ~/Desktop/www (master)
$ git push origin master
Everything up-to-date

whoway@XXX MINGW64 ~/Desktop/www (master)
$ git log
commit 194057b65f837e4f5489a109ddf4e1e79ba84338 (HEAD -> master, origin/master, origin/HEAD)
Author: whoway <7799986[email protected]>
Date:   Tue Mar 8 11:15:40 2022 +0000

    Initial commit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  • 参考资料:https://support.huaweicloud.com/usermanual-codehub/devcloud_hlp_0960.html
  • 参考资料:Gitee:https://gitee.com/help/articles/4235#article-header4
    • 注意,免费用户没有这个权限,所以报错如下
whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitattributes
        temp.pdf

nothing added to commit but untracked files present (use "git add" to track)

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ ls
README.en.md  README.md  temp.pdf

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git add .

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git commit -m "add lfs"
[master b55b202] add lfs
 2 files changed, 4 insertions(+)
 create mode 100644 .gitattributes
 create mode 100644 temp.pdf

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ ls
README.en.md  README.md  temp.pdf

whoway@XXXXX MINGW64 ~/Desktop/www (master)
$ git push origin master
Remote "origin" does not support the LFS locking API. Consider disabling it with                                                  :
  $ git config lfs.https://gitee.com/HACV/www.git/info/lfs.locksverify false
batch request: [session-0c448cab] Permission to 'HACV/www' denied
Message: LFS only supported repository in paid enterprise.: exit status 1
Uploading LFS objects:   0% (0/1), 0 B | 0 B/s, done
error: failed to push some refs to '[email protected]:HACV/www.git'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

# GItHub可以

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ ls
1111.jpg  README.md  whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git add 1111.jpg

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ ls
1111.jpg  README.md  whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   1111.jpg

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    .github/workflows/vuepress-deploy.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        whoway.pdf


whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git lfs track whoway.pdf
Tracking "whoway.pdf"

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ ls
1111.jpg  README.md  whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   1111.jpg

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    .github/workflows/vuepress-deploy.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitattributes
        whoway.pdf


whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ cat .gitattributes
whoway.pdf filter=lfs diff=lfs merge=lfs -text

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git push origin main
Everything up-to-date

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git add .gitattributes

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   .gitattributes
        new file:   1111.jpg

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    .github/workflows/vuepress-deploy.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        whoway.pdf


whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git commit -m "dddd"
[main 474b9f2] dddd
 2 files changed, 1 insertion(+)
 create mode 100644 .gitattributes
 create mode 100644 1111.jpg

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git push origin main
Counting objects: 4, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 139.64 KiB | 475.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To github.com:whoway/demo.git
   70d853a..474b9f2  main -> main

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ lls
bash: lls: command not found

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ ls
1111.jpg  README.md  whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git lfs ls-files

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git pull
Already up to date.

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ ls
1111.jpg  README.md  whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    .github/workflows/vuepress-deploy.yml

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        whoway.pdf

no changes added to commit (use "git add" and/or "git commit -a")

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git add .

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git commit -m "ss2"
[main 6fcb70e] ss2
 2 files changed, 3 insertions(+), 79 deletions(-)
 delete mode 100644 .github/workflows/vuepress-deploy.yml
 create mode 100644 whoway.pdf

whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git push origin main
Uploading LFS objects: 100% (1/1), 191 MB | 1.6 MB/s, done
Counting objects: 3, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 376 bytes | 376.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:whoway/demo.git
   474b9f2..6fcb70e  main -> main


whoway@XXXXX MINGW64 ~/Desktop/demo (main)
$ git blame whoway.pdf
6fcb70ee (HACV 2022-03-23 17:05:23 +0800 1) version https://git-lfs.github.com/s                                                  pec/v1
6fcb70ee (HACV 2022-03-23 17:05:23 +0800 2) oid sha256:018b9e94b15ee66eab72c1328                                                  a96bf8c3bb9745db332fbf7e3eec52f15f3282e
6fcb70ee (HACV 2022-03-23 17:05:23 +0800 3) size 190648578

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

# 附录2-高标准

# 如何规范你的Git commit?

​ 初期我们在互联网上搜索了大量有关git commit规范的资料,但只有Angular规范是目前使用最广的写法,比较合理和系统化,并且有配套的工具(IDEA就有插件支持这种写法)。最后综合阿里巴巴高德地图相关部门已有的规范总结出了一套git commit规范。

# Git提交规范

规范1:Git commit 提交规范 (opens new window)

规范2:Git使用emoji (opens new window),常发生在GitHub

:单词: 解释
🎨 :art: 改进结构和格式化代码
⚡️:zap: 性能优化
🔥fire 溢出

# 零碎的学习.git checkout --

  • file命令中的--很重要,没有--,就变成了“切换到另一个分支”的命令「类似cd --这个Linux命令

    • 我们在后面的分支管理中会再次遇到git checkout命令
  • 命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:「其实,我不加--也可以,git check ./*全部,git checkout readme.md一个」

    • 一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;

# git统计代码行数

# 1.阅读源码-统计github本地仓库的代码行数

git ls-files | xargs wc -l
1
  • git ls-files 显示有关索引和工作树中文件的信息
git ls-files
1
  • Linux wc命令用于计算字数。
    • -l--lines 显示行数。

# 参考资料