{% note %}
阅读进度 Git - Undoing Things
✅ 2.1-2.3;2.5-2.7; 🕒 7.7,2.4
✅ 3.1;3.2; 3.5;3.6; 🕒 3.3-4
🕒 5.1-5.4; 🕒 6.1-6.6
{% endnote %}
基本操作
config
可用git config
命令设置git配置:
|
|
也可在配置文件~/.gitconfig
中直接编辑,如添加alias可写入:
|
|
diff
-
git diff
可以查看工作目录与「暂存区」或「仓库(if not staged)」之间的文件差异. -
git diff --staged
可以查看「暂存区」和「仓库」之间的文件差异
|
|
- 可以使用
git difftool
调用其它编辑器查看修改内容; 使用git difftool --tool-help
查看受支持的编辑器。
commit
git commit -a
的-a
选项可以自动将所有已跟踪的文件加入到暂存区。
Adding the
-a
option to thegit commit
command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip thegit add
part:
tagging
标签分为 Annotated 和 Lightweight 两种类型。其中 Annotated 需要添加 commit 信息, 保存的内容更多。
A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit.
Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.
标签查看
|
|
标签创建
|
|
标签删除
|
|
提取对应标签内容
|
|
Remote Push
git push
默认不会同步标签的添加和删除信息,需要手动添加。
同步标签创建信息
|
|
同步标签删除信息
|
|
rm
使用cached
选项删除已经staged的文件
|
|
log
输出格式
-p
选项将打印出diff
信息;--stat
提交统计信息(statistics);--pretty
将打印出格式化的信息。--graph
将以ASCII 图形的方式打印出分支和合并历史
|
|
Option | Description |
---|---|
-p |
Show the patch introduced with each commit. |
--stat |
Show statistics for files modified in each commit. |
--shortstat |
Display only the changed/insertions/deletions line from the --stat command. |
--name-only |
Show the list of files modified after the commit information. |
--name-status |
Show the list of files affected with added/modified/deleted information as well. |
--abbrev-commit |
Show only the first few characters of the SHA-1 checksum instead of all 40. |
--relative-date |
Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format. |
--graph |
Display an ASCII graph of the branch and merge history beside the log output. |
--pretty |
Show commits in an alternate format. Option values include oneline, short, full, fuller, and format (where you specify your own format). |
--oneline |
Shorthand for --pretty=oneline --abbrev-commit used together. |
日志筛选
|
|
Option | Description |
---|---|
-<n> |
Show only the last n commits |
--since , --after |
Limit the commits to those made after the specified date. |
--until , --before |
Limit the commits to those made before the specified date. |
--author |
Only show commits in which the author entry matches the specified string. |
--committer |
Only show commits in which the committer entry matches the specified string. |
--grep |
Only show commits with a commit message containing the string |
-S |
Only show commits adding or removing code matching the string |
使用git log -- path/to/file
可将日志限定在某一文件或文件夹。注意路径必须写在最后。
分支管理
分支查看与管理
|
|
分支切换
|
|
分支合并
|
|
Rebase
Suppose the commit history is as following:
A---B---C topic*
/
D---E---F---G master
The rebase command
|
|
will result in:
|
|
Working with Remote
远程分支管理与查看
查看仓库
|
|
管理仓库
|
|
仓库获取与
|
|
提取分支
|
|
设置track
|
|
查看track
|
|
删除分支
|
|
Submodule
将一个仓库添加为submodule, 类似于git clone
|
|
获取一个含有submodule的git仓库
|
|
以上命令可合并为一条
|
|
Draft
Files Management
|
|
Remote Branches
|
|
Git on the Server
|
|