0. 介绍
这个备忘单总结了常用的Git 命令行,用来方便快速查找。
1. 什么是Git。
Git 是一个开源代码分布式版本控制系统,它为了方便在电脑上使用GitHub 的活动。
2. 安装Git
Github 提供了桌面端,它包含一个基本的文件操作的图形操作界面。 Github 也提供了一个为高级情况下自动更新命令行Git版本。
Windows 下GitHub: htps://windows.github.com
Mac 下GitHub:htps://mac.github.com
Github 所有平台:htp://git-scm.com
3. 配置工具
$git config --global user.name "[name]"
设置用户名
$git config --global user.email "[email address]"
设置用户邮箱
$git config --global color.ui auto
设置颜色为自动
4. 创建目录
$ git init [project-name]
创建一个新的本地文件夹和项目名字
$git clone [url]
下载一个项目
5. 修改
$git status
列出所有新的或者修改的文件来提交
$git diff
显示没staged文件不同
$git add [file]
快照文件为准备不同版本
$git diff --staged
显示文件staging 和最后版本的不同
$git reset [file]
unstages 文件,但是保存内容
$git commit -m "[descriptive message]"
记录文件快照到文件版本历史中
6. 更改分支
$ git branch
列出本文件中所有的本地分支
$ git branch [branch-name]
创建一个新分支
$ git checkout [branch-name]
切换到指定的分支 并且更新工作目录
$ git merge [branch]
组合指定的分支历史到当前的分支
$ git branch -d [branch-name]
删掉指定的分支
7. 改名
$ git rm [file]
$ git rm --cached [file]
删掉文件从版本控制上,但是保留本地文件
$ git mv [file-original] [file-renamed]
改名并准备commit
8. 排除tracking
*.log
build/
temp-*
$git ls-files --other --ignored --exclude-standard
列出所有的忽视的文件
9. 保存fragments
$ git stash
$ git stash pop
$git stash list
$git stash drop
10. 查看历史
$ git log
列出所有的当前分支版本历史
$ git log --follow [file]
列出所有版本历史,包括重命名
$ git diff [first-branch] ... [second-branch]
列出不同分支的内容的不同
$ git show [commit]
输出指定commit的元数据和内容改变
11. Redo commits
$ git reset [commit]
Undo 所有的commits after 指定的commit,保存本地的修改
$ git reset --hard [commit]
放弃所有的历史和修改,回到指定的commit
12. 同步更改
$ git fetch [bookmark]
下载所有的历史从文件bookmark
$ git merge [bookmark]/[branch]
组合bookmark的分支到本地分支
$ git push [alias][branch]
上传所有的本地分支commits 到Github
$ git pull
下载所有的bookmark 历史并组合更改。
stage:
Reference:
https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf