参考:苏玲《玩转Git三剑客》
1.说明
Git--分布式版本控制系统
2.安装
https://git-scm.com/
3.配置
git config --global user.name ayusue
git config --global user.email ayusue@163.com
git config --local
git config --global
git config --system
4.创建仓库
git 代码路径
git init
cd 文件夹
git init project_name
cd project_name
5.工作区 暂存区
git add filename filename2
git commit -m"message"
git commit -am"message"
git status
git log
6.重命名
git mv old_filename new_filename
7.gitlog
git log --oneline --all --graph
git log -n4
git branch -av #查看本地分支
git checkout -b new_branch 提交ID #新建分支
git checkout branch_name #切换分支
8.工具gitk
9.".git"目录
.git/HEAD
.git/config
.git/refs/
.git/refs/heads/
.git/refs/temp/
.git/objects
git cat-file -t 文件ID #查看object类型
git cat-file -p 文件ID #查看object内容
10.git文件结构
commit #提交
tree #文件夹
blob #文件
11.练习
12.分离头指针
git checkout commit_ID #变更没有绑定任何分支
13.HEAD和branch
git diff commit_ID_1 commit_ID_2
git diff HEAD HEAD^
git diff HEAD HEAD^^
git diff HEAD HEAD~2
14.删除分支
git branch -d commit_ID
git branch -D commit_ID
15.修改commit的message
git commit --amend
16.修改commit的message(2)
git rebase -i commit_ID
reward commit_ID message
17.合并commit
git rebase -i commit_ID
pick commit_ID_3
squash commit_ID_2
squash commit_ID_1
pick commit_ID
18.合并commit(2)
git rebase -i commit_ID
pick commit_ID_3
squash commit_ID_1
pick commit_ID_2
19.diff 暂存区和HEAD
git diff --cached
20.diff 工作区和暂存区
git diff
git diff -- filename filename2
21.HEAD->暂存区
git reset HEAD
22.暂存区->工作区
git checkout -- filename filename2
23.撤销暂存区
git reset HEAD -- filename
24.撤销提交
git reset --hard commit_ID
25.diff 已提交文件
git diff branch_name branch_name_2
git diff commit_ID commit_ID_2
git diff branch_name branch_name_2 -- filename
26.删除文件
git rm filename
27.stash另存
git stash
git stash list
git stash apply #还原后删除stash list
git stash pop #还原后保留stash list
28.指定不管理文件
vi .git/.gitignore
*.doc
doc/
29.远端备份到本地
git clone --bare 路径/.git project_name
git clone --bare file://路径/.git project_name
git remote add remote_name file://路径
git push --set-upstream remote_name branch_name