Git常用命令
转自:https://blog.csdn.net/ahjxhy2010/article/details/80047553
1.查看某个文件修改历史
git log filename #查看fileName相关的commit记录 git log -p filenam # 显示每次提交的diff git show c5e69804bbd9725b5dece57f8cbece4a96b9f80b filename #只看某次提交中的某个文件变化,commit-id 文件名
git log --oneline #每笔提交只显示一行
2.查看暂存区
git ls-files //查看暂存区中文件信息
如何查看暂存区中bb.txt文件内容是什么?
git ls-files -s -- 文件名 或者直接 git ls-files -s //然后通过Blob对象,查询bb.txt里面的内容: git cat-file -p 6cef
git stash //可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作 //把工作区和暂存区的内容都存起来 git stash list //查看暂存内容 git stash pop //恢复的同时把stash内容也删了
git stash clear //清空所有的内容
git stash drop stash@{0} //这是删除第一个队列
3.commit
//打印所有commit记录 git log //查看修改的文件具体内容 git show commitId //查看修改文件的列表
git show commitId --stat
//查看某次commit中具体某个文件的修改: git show commitId fileName
//提交不会产生新的commitID
git commit --amend
4.分支操作
创建分支:git branch <name>
切换分支:git checkout <name>
或者git switch <name>
创建+切换分支:git checkout -b <name>
或者git switch -c <name>
git branch -d <name>
合并某分支到当前分支:git merge <name>
6.删除文件的工作区所有更改-回退
% git checkout -- filename
情况1:在工作区做了修改,并未添加到暂存区,想撤销工作区的修改,用 git restore file;
情况2:在工作区做了修改,并用git add 添加到了暂存区,未提交;想撤销,分两步,1.先撤销暂存区的修改,用 git reset, 2.然后参考情况1撤销工作区的修改;
通过 git reset 文件名
命令可以撤销指定文件的 git add
操作,即这个文件在暂存区的修改。
通过 git reset
命令可以撤销之前的所有 git add
操作,即在暂存区的修改。
情况3:在工作区做了修改,且git add git commit添加并提交了内容,想撤销本次提交,直接用 git reset --hard HEAD^回退版本,即可保证工作区,暂存区,版本库都是上次的内容。(这样修改的代码会没有,慎用!)
git reset --soft HEAD^,只是将commit操作回退,add .和工作区内容都在。
删除所有工作区的修改:git checkout . # 丢弃所有修改或删除,不影响新增或未跟踪的文件。会递归下级目录
https://marklodato.github.io/visual-git-guide/index-zh-cn.html?no-svg
7.统计
https://blog.csdn.net/beibeix2015/article/details/111868461
git log --author="author" //查看某个人的所有提交,用于总结报告 git log --reverse --author="author" //逆序查看 git log --author="zhangphil" --oneline | wc -l //总的提交次数
8.调整commit的顺序
假设想把下述倒数第3个提交149fa24挪到第一个,
git rebase -i HEAD~3 #再通过dd剪切一行,通过p粘贴
注意上图展示的提交是倒序,最晚提交的在最下面。 前提至少这几笔提交没有先后依赖关系,否则不会成功。
相关文章
- [Git] An efficient GIT workflow for mid/long term projects
- [Git] git shortlog 找出最懒的程序员
- git初学常用命令解析
- git常用命令
- Git常用命令
- Git fetch和git pull的区别
- [Git] Use git add --patch for better commit history and mitigating bugs
- [Practical Git] Diagnose which commit broke something with git bisect
- [Practical Git] Format commit history with git log arguments
- Git远程02:git clone都做了什么
- Git远程01:git remote相关操作
- git的最常用命令总结
- git之win安装git和环境配置及常用命令总结
- 【学习总结】Git小结 (Mac版)
- 【学习总结】Git学习-GIT工作流-千峰教育(来自B站)
- [Git] A better git process
- [Git] Recover Local Changes from `git reset --hard` with `git reflog`
- [Git] Use git add --patch for better commit history and mitigating bugs
- [Git] Submodule
- Git常用命令一
- git 版本历史
- Git知识总览(二) git常用命令概览
- git新建分支及提交代码到分支
- Git常用命令总结
- 一文吃透 VS Code+Git 操作(vs code中git的相关配置与使用)
- git常用命令总结
- 【Git技巧】第十篇 解决每次git clone都需要输入账号密码
- GIT ---- 常用 Git 命令清单