本地仓库命令
1.历史 log/relog
commit后才算一个历史版本,仅add不算
1.1 log
# 从最新提交开始,显示所有提交记录(hash,作者信息,标题和时间)
git log
# 输出概要日志,等于git log --pretty=oneline --abbrev-commitgit log --oneline
# 查看
git log [--reverse|--oneline]
## --reverse 按时间正序排列的信息
## --oneline 每个提交在一行内显示
## --graph 提供类似 GUI 工具的 log 展示
## --all 展示所有
## --grep 过滤 --grep='homepage'
## --author 显示某用户的提交 --author="username"
## n 指定最近几个提交可带 -/+ 数字 git log n 5
## -p 显示某文件的所有修改 git log -p <file>
git log --oneline -5
git log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'
查找 Commits 和更改
# 通过 commit 信息查找 (所有分支)
git log --all --grep='<search term>'
# 通过 commit 信息查找 (包含 reflog)
git log -g --grep='<search term>'
# 通过更新的内容查找
git log -S '<search term>'
# 通过日期范围查找
git log --after='DEC 15 2019' --until='JAN 10 2020'
1.2 reflog
git reflog 记录所有行为,包括 rebase,merge, reset
当不小心硬回滚或变基错误,都可找到commit,然后回滚。只在本地有用。
git reflog
## reflog查看本地以往版本号
git reflog -5
2.搜索 grep
# 从当前目录的所有文件中查找文本内容
git grep