Git Command
1.7 起步 - 获取帮助
- 
git help - git help <verb>
- git <verb> --help
- git <verb> -h 短格式帮助
 
- 
git config - 
git config --list 
 //显示所有配置
- 
git config --show-origin --list 
 //显示所有配置;以及原始类型
- 
git config --list --show-origin 
 //显示所有配置;以及原始类型
 
- 
2.2 Git 基础 - 记录每次更新到仓库
- 
在已存在目录中初始化仓库 - git init 初始化
- git add *.c //跟踪新文件
- git commit -m ‘initial project version’
 
- 
克隆现有的仓库 - git clone <URL> [local name] //URL支持git:// http://协议
- git status //查看状态
- git add <file name> //添加跟踪
 
- 
状态简览 - git status -s
 
- 
忽略文件 (.gitignore) 
 文件 .gitignore 的格式规范如下:- 所有空行或者以 # 开头的行都会被 Git 忽略。
- 可以使用标准的 glob 模式匹配,它会递归地应用在整个工作区中。
- 匹配模式可以以(/)开头防止递归。
- 匹配模式可以以(/)结尾指定目录。
- 要忽略指定模式以外的文件或目录,可以在模式前加上叹号(!)取反。
- Demo:  1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17# 忽略所有的 .a 文件 
 *.a
 # 但跟踪所有的 lib.a,即便你在前面忽略了 .a 文件
 !lib.a
 # 只忽略当前目录下的 TODO 文件,而不忽略 subdir/TODO
 /TODO
 # 忽略任何目录下名为 build 的文件夹
 build/
 # 忽略 doc/notes.txt,但不忽略 doc/server/arch.txt
 doc/*.txt
 # 忽略 doc/ 目录及其所有子目录下的 .pdf 文件
 doc/**/*.pdf
 
- 
查看已暂存和未暂存的修改 - git diff  (git diff --staged  || git diff --cached)
 此命令比较的是工作目录中当前文件和暂存区域快照之间的差异
- git difftool --tool-help
 使用 git difftool --tool-help 命令来看你的系统支持哪些 Git Diff 插件
 
- git diff  (git diff --staged  || git diff --cached)
- 
提交更新 - git commit
- 使用 git config --global core.editor 命令设置你喜欢的编辑器。
- commit 命令后添加 -m 选项,将提交信息与命令放在同一行
 
 
- git commit
- 
跳过使用暂存区域 - git commit 加上 -a 选项;跳过 git add 步骤
 
- 
移除文件 - git rm
- 果要删除之前修改过或已经放到暂存区的文件,则必须使用强制删除选项 -f(译注:即 force 的首字母)
 
- git rm --cached README
- 我们想把文件从 Git 仓库中删除(亦即从暂存区域移除),但仍然希望保留在当前工作目录中
 
 
- git rm
- 
移动文件 - git mv file_from file_to
 
2.3 Git 基础 - 查看提交历史
- 
查看提交历史 - git log
- git log -p[patch] -2 显示最近的两次提交差异
- git log  --stat  --pretty
 demo: git log --pretty=format:“%h - %an, %ar : %s”
 
- 
限制输出长度 - git log --since=2.weeks
 
2.4 Git 基础 - 撤消操作
- 
撤消操作 - git commit --amend   1 
 2
 3
 4//最终你只会有一个提交——第二次提交将代替第一次提交的结果。 
 $ git commit -m 'initial commit'
 $ git add forgotten_file
 $ git commit --amend
 
- git commit --amend   
- 
取消暂存的文件 - git reset HEAD <file>
- git rm --cache <file>
 
- 
撤消对文件的修改 - git checkout – <file>
 请务必记得 git checkout -- <file> 是一个危险的命令。 你对那个文件在本地的任何修改都会消失——Git 会用最近提交的版本覆盖掉它。 除非你确实清楚不想要对那个文件的本地修改了,否则请不要使用这个命令。
 
- git checkout – <file>
2.5 Git 基础 - 远程仓库的使用
- 查看远程仓库
- git remote -v
 -v,会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL
 
- git remote -v
- 添加远程仓库
- git clone https://github.com/schacon/ticgit
- git remote add <shortname> <url>
 
- 从远程仓库中抓取与拉取
- git fetch <remote>
 将数据下载到你的本地仓库——它并不会自动合并或修改你当前的工作。 当准备好时你必须手动将其合并入你的工作
- git pull
 自动抓取后合并该远程分支到当前分支
 
- git fetch <remote>
- 推送到远程仓库
- git push <remote> <branch>
 
- 查看某个远程仓库
- git remote show <remote>
 
- 远程仓库的重命名与移除
- git remote rename
 $ git remote rename oldName newName
 
- git remote rename
- git remote remove 或 git remote rm //移除一个远程仓库
2.6 Git 基础 - 打标签
[------------ 未完 待续 ------------]
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 水 流 记!






