惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Secure Thoughts
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
博客园 - 司徒正美
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
B
Blog
The GitHub Blog
The GitHub Blog
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
Martin Fowler
Martin Fowler
博客园 - 叶小钗
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
S
Securelist
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
T
Threat Research - Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
Cloudbric
Cloudbric
The Cloudflare Blog
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Hacker News: Front Page
腾讯CDC
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
The Last Watchdog
The Last Watchdog
G
GRAHAM CLULEY
Google Online Security Blog
Google Online Security Blog
T
The Blog of Author Tim Ferriss

Coding Your Life

lib库开发的一款PDF处理小工具 | Coding Your Life mirror-cli | Coding Your Life 最长递增子序列算法 | Coding Your Life webpack5 模块联邦技术 | Coding Your Life webpack基础配置详解 | Coding Your Life canvas实现代码雨效果 | Coding Your Life 使用MessageChannel模拟React优先级执行队列 | Coding Your Life vue3 和 react 虚拟dom | Coding Your Life ES6中Reflect对象与Proxy结合实现代理和响应式编程 | Coding Your Life 前端技术分享MediaRecord实现运动相机 | Coding Your Life react基础概念 | Coding Your Life 微信小程序使用canvas创建像素头像 | Coding Your Life 前端基础概念 | Coding Your Life 中高级前端须注意的40条移动端H5坑位指南 | Coding Your Life native-code-push 热更新配置 | Coding Your Life push-server 热更新常用命令速查表 | Coding Your Life 高效的js片段 | Coding Your Life
Git 常用命令速查表 | Coding Your Life
Sir_Liu · 2019-11-10 · via Coding Your Life

git 常用术语

  • master 默认开发分支
  • origin 默认远程版本库
  • Index/Stage 暂存区
  • Workspace 工作区
  • Repository 仓库区(或本地仓库)
  • Remote 远程仓库

git 创建代码库

在当前目录新建一个git代码库

1
2
3
4
5
6
7
$ git init 
$ git add README.md
$ git commit -m "first commit"

$ git remote add origin 【远程仓库地址】
$ git push -u origin master
$

已有本地仓,链接远程仓库

1
2
$ git remote add origin 【远程仓库地址】
$ git push -u origin master

指定一个目录,将其初始化为git代码库

1
$ git init [project-name]

下载一个项目和它的整个代码历史

1
$ git clone [url]

下载一个项目和他最近一次的提交(当要克隆的项目过大,出现TimeOut问题时谨慎使用 )

1
$ git clone --depth 1 [url]

这种方法克隆的项目只包含最近commit的一个分支,体积很小,但会产生另外一个问题,他只会把默认分支clone下来,其他远程分支并不在本地,所以这种情况下,需要用如下方法拉取其他分支:

1
2
3
$ git remote set-branches origin [remote_branch_name]
$ git fetch --depth 1 origin [remote_branch_name]
$ git checkout [remote_branch_name]

git 配置信息

Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。

显示当前的git配置信息

1
$ git config --list

编辑git配置文件

1
$ git config -e [--global]

设置提交代码的用户信息

1
2
$ git config [--global] user.name  "[name]"
$ git config [--global] user.email "[email address]"

git 常用命令

增加、删除、修改文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

$ git status

$ git diff

$ git add [file1] [file2] ...

$ git add [dir]

$ git add .


$ git add -p

$ git rm [file1] [file2] ...

$ git rm --cached [file]

$ git rm -f --cached [file]

$ git mv [file-originName] [file-newName]

git 代码提交

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

$ git commit -m [message]

$ git commit [file1] [file2] ... -m [message]

$ git commit -a

$ git commit -v


$ git commit --amend -m [message]

$ git commit --amend [file1] [file2] ...

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

$ git branch

$ git branch -r

$ git branch -a

$ git branch [branch-name]

$ git branch --track [branch] [remote-beanch]

$ git branch -d [branch-name]

$ git push origin --delete [branch-name]
$ git branch -dr [remote-branch]

$ git checkout -b [branch]

$ git checkout -b [new-branch] [origin-branch]

$ git checkout [branch-name]

$ git checkout -

$ git branch --set-upstream [branch] [remote-branch]

$ git merge [branch]

$ git rebase <branch>

$ git cherry-pick [commit]

git 标签

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

$ git tag

$ git tag <tagname>

$ git tag -d <tagname>

$ git push origin :refs/tags/[tagname]

$ git show [tag]

$ git push [remote] [tag]

$ git push [remote] --tag

$ git checkout -b [branch] [tag]

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
41

$ git status

$ git log

$ git log --stat

$ git log -S [keyword]

$ git log [tag] HEAD --pretty=format:%s

$ git log [tag] HEAD --grep feature

$ git log --fellow [file]
$ git whatchchange [file]

$ git log -p [file]

$ git log -5 --pretty --online

$ git shortlog -sn

$ git blame [file]

$ git diff

$ git diff --cached [file]

$ git diff HEAD

$ git diff [first-branch]...[second-branch]

$ git diff --shortstart "@{0 day ago}"

$ git show [commit]

$ git show --name-only [commit]

$ git show [commit]:[filename]

$ git reflog

git远程操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

$ git fetch [remote]

$ git pull [remote] [branch]

$ git remote -v

$ git remote show [remote]

$ git remote add [short-name] [url]

$ git push [remote] [branch]

$ git push [remote] --force

$ git push [remote] --all

$ git push <remote>:<branch/tag-name>

$ git push --tag

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

$ git reset --hard HEAD

$ git checkout HEAD <file>

$ git revert <commit>

$ git log --before="1 days"

$ git checkout [file]

$ git checkout [commit] [file]

$ git checkout .

$ git reset [file]

$ git reset --hard


$ git reset [commit]

$ git reset --hard [commit]

$ git reset --keep [commit]


$ git revert [commit]

$ git stash
$ git stash pop

git 其他

1
2

$ git archive

参考链接: 点我查看

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Coding Your Life