起步
Git 认知
- Snapshots, Not Diff erences
- Nearly Every Operation Is Local
- Everything in Git is check-summed before it is stored and is then referred to by that checksum
- Git Generally Only Adds Data
- The Three States :the Git directory, working directory, and the staging area
- Git 基本工作流程 :增删改(working directory)-> 存储快照(staging area)-> 提交(Git directory)
- Git 文件状态 :untracked、unmodified、modified、staged
配置 Git
/etc/gitconfig :every user,$ git config —system
~/.gitconfig or ~/.config/git/config :specified user, $ git config —global
.git/config :specified repository, $ git config
|
|
实战(一)
- 新项目
|
|
- 查看文件状态
|
|
- 克隆已有的项目
|
|
- 忽略要处理的文件 :在 .gitignore 中创建要忽略文件的正则表达式,其中 # 开头为注释
|
|
- 比较 :$ git diff,$ git diff —staged,$ git diff —cached
- 跳过快照区步骤 :Git 自动提交已经追踪到的但没有存储到快照区(git add)的新文件 -> $ git commit -a -m ‘added new benchmarks’
- 删除文件
|
|
- 更改文件
|
|
- 查看日志
|
|
- 撤消或重新提交
|
|
- Git 命令别名
|
|
与远程进行协作
- 添加远程仓库别名 : $ git remote add pb https://github.com/paulboone/ticgit
- 显示别名及其代表的URL :$ git remote -v
- 通过别名获取仓库 :$ git fetch pb
- 推送到远程仓库 :$ git push origin master
- 检查远程仓库状态 :$ git remote show origin
- 重命名远程仓库别名 :$ git remote rename pb paul
- 删除别名 :$ git remote rm paul
为项目添加标签
Git 使用两种类型的标签 :轻量级的(lightweight)和带注解的(Annotated)
轻量级 :为某次特别的提交而添加的标签
带注解 :包含所有必要的信息,像是标签的作者、日期、电邮、注解和 GPG 等(更像是一次版本?)
- 列出标签 :$ git tag,$ git tag -l ‘v1.8.5*’ # 只列出1.8.5系列的版本
- 创建 Annotated 标签 :$ git tag -a v1.4 -m ‘my version 1.4’
- 列出标签信息 :$ git show v1.4
- 创建 Lightweight 标签 :$ git tag v1.4-lw
- 推送标签 :$ git push origin v1.5,$ git push origin —tags (默认情况下,推送不包含标签)
- 签出某个标签的版本 :$ git checkout -b version2 v2.0.0(切记,标签默认不会被推送)