git 常用命令

110 阅读1分钟

log

# 格式化日志
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --date=format:'%Y-%m-%d %H:%M:%S' -n 20

git log --graph --pretty=oneline --abbrev-commit

git-log.jpg

show

# 查看某次提交差异
git show commit-id

branch

# 查看本地分和远程所有分支
git branch -a

# 基于当前分支末梢新建分支但并不切换分支
git branch branch-name

# 基于当前分支末梢新建分支并切换至该分支
git checkout -b branch-name

# 基于某次提交、分支或标签创建新分支
git branch branch-name commit-id

# 删除本地分支
git branch -d branch-name

# 删除远程分支
git push origin --delete branch-name

reset

# 撤销暂存区的修改,重新放回工作区
git reset --hard

# 撤销到指定commit-id
git reset commit-id --hard

stash

# 将文件修改添加至暂时储藏库
git stash save "temp local store"

# 查看本地储藏列表
git stash list

# 恢复储藏到暂存区
git stash pop

revert

# 还原某次提交
git revert commit-id

# 还原上一次提交
git revert HEAD

tag

# 查看所有标签
git tag

# 新建标签
git tag v1.0.0

# 在指定提交中新建标签
git tag v1.0.0 commit-id