常用git命令:
1.配置项:
git config --global --help
一般配置项为用户名 邮箱 对比工具 命令缩写 其他现在还没有用到;
2. 新建初始化库
git init
git clone url
3.代码提交
git add .
git rm [file]
git rm --cached [file] 停止追踪文件
git commit -m
git commit --amend
git commit
git cherry-pick commitId
4.branch
git branch
git branch -r
git branch -a
git branch [branch-name]
git checkout -b [branch]
git branch [branch] [commit]
新建一个分支并与远程分支建立track关系
git branch --track [branch] [remote-branch]
git checkout -b [branch-name] [remote-branch]
git checkout [branch-name]
git checkout - //切换到上一个分支
在现有分支与指定的远程分支之间建立track 关系
git branch --set-upstream [branch] [remote-branch]
git merge [branch]
git cherry-pick [commit]
git branch -d [branch-name]
git push origin --delete [branch-name]
5.log
git log
git log -n
git log --stat
git log --follow [file] //显示某个文件的版本历史
git log -p [file] //显示指定文件相关的每一次diff
git shortlog -sn //显示所有提交过的用户,按提交次数排序
git blame [file] //显示指定文件是什么人在什么时间修改过
git reflog
git diff //暂存区与工作区的差异
git diff --cached [file]
git diff HEAD //工作区与仓库最新的commit的差异
git diff [first-commit]…[second-commit]
git diff --shortstat “@{0 day ago}” //显示今天你写了多少行代码
git show [commit] //显示某次提交的元数据和内容变化
git show --name-only [commit] //显示某次提交发生变化的文件
git show [commit]:[filename] //显示某次提交时,某个文件的内容
6.push and pull
git push remote branch
git pull remote branch
git fetch [remote] 更新本地仓库
git remote -v
git rebase
git merge
7.tag
git tag [tag]
8.代码回退
git checkout – .
git checkout [file]
git checkout [commit] [file]
git reset [file] //从暂存区中捞出误增加的文件
git reset [commit]
git reset --hard
git stash
git stash save -u “statement”
git stash list
git stash pop stash@{0}
git revert commit