git常用命令总结

453 次浏览次阅读
没有评论

git 命令结合
撤销本地修改文件(尚未提交到缓存区)不包括新增文件

git checkout .
git checkout [filename]

回退到已提交的某个版本

git log 查看版本号
git reset --hard [commit-hashcode]  

#[commit-hashcode] 是某个 commit 的哈希值,可以用 git log 查看

从一个分支 A 切换到另一个分支 B 后,对切换后的 B 分支进行 pull 操作,因为 pull 操作实际上包含了 fetch+merge 操作,在执行 merge 操作时,由于很长时间没有对 B 分支执行过 pull/merge 操作,本地的 B 分支库与 remote 中的 B 分支库中的差异很大(且这些差异是其他 同事开发的文件),merge 时产生冲突,使得 B 分支的状态为 merging,其实是指 merge 失败,还停留在 merge 状态,也不能执行 pull 操 作。这时没有解决冲突,而是从 B 分支上执行 checkout/switchto 操作,试图再切换其他分支时报 error: you need to resolve your current index first
退回 merge 前吧
git reset --merge  

拉去远程分支

git fetch 
git checkout 分支名 

git 删除本地分支

git branch -d 分支名
git branch -D 分支名
git branch -l[a] 列出本地所有分支 

提交

git add .
git commit -m 'update'
git push origin 分支名 

日志

git log // 普通查日志
git log --oneline // 简化输出
git log --pretty=oneline -3 // 指定输出行数
git shortlog // 输出汇总信息,以作者进行分类
git shortlog -s  // 统计每个作者的 commit 数量
git shortlog -n // 用来对统计的量进行倒序排列
git log --author [authorname]// 用来过滤 commit, 限定输出给定的用户 
正文完
 0
评论(没有评论)