Git学习笔记

初次运行 Git 前的配置

1
2
3
4
5
6
7
8
9
10
11
12
**用户信息**
git config --global user.name "Tony Huang"
git config --global user.email huang690910789@gmail.com
**文本编辑器**
git config --global core.editor vim
**差异分析工具**
git config --global merge.tool vimdiff
**查看配置信息**
git config --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
**创建版本库**
git init
**查看当前状态**
git status
**查看文件区别**
git diff filename
**把文件添加到版本库**
git add filename
git commit -m "descript"
**版本回退**
git log //查看提交历史
git reflog //查看未来
git reset --hard commit_id //回到历史
git checkout -- file //撤销所有修改
git rm file //删除文件
**远程仓库**
需在本机生成id_rsa.pub文件添加到github设置上,才可使用ssh,否则使用https
git remote add origin git@server-name:path/repo-name.git //关联一个远程库
git push -u origin master //关联第一次提交
git push origin master //推送最新修改
git clone git@server-name:path/repo-name.git //克隆一个仓库

分支管理

1
2
3
4
5
6
7
8
9
10
11
**创建及管理分支**
git branch //查看分支
git branch <name> //创建分支
git checkout <name> //切换分支
git checkout -b <name> //创建+切换分支
git merge <name> //合并某分支到当前分支
git branch -d <name> //删除分支
**解决冲突**
手动修改后提交
git log --graph //查看分支合并图

备注

git使用简易指南
码云平台帮助文档
Pro Git(中文版)
英文版Tutorials
常用 Git 命令清单
Git 工作流程
常用 Git 命令清单
Git远程操作详解
在线git学习
沉浸式学 Git
GitHub的黑魔法大集合
猴子都能懂的git入门
廖雪峰-Git教程

文章目录
  1. 1. 初次运行 Git 前的配置
  2. 2. 基础命令
  3. 3. 分支管理
  4. 4. 备注
,