Git命令总结

2019-05-15  本文已影响0人  Lcap

存储空间 说明
Workspace 工作空间
(index)->Stage 缓存空间(使用git add添加)
(HEAD)->Repo 存储仓库(使用git commit添加)
Num Command Description
1 $git branch <new branch name> 新建一个开发分支
2 $git branch 查看本地所有branch
3 $git branch -r 查看远端所有branch
4 $git branch -a 查看本地和远端所有branch
5 $git branch <branch> <commitID> 以指定commit拉一条分支
6 $git checkout <branch name> 切换至指定分支
7 $git checkout -b <new branch name> 新建分支,并切换至该分支
8 $git branch -d <branch name> 删除已经完成merge master的分支
9 $git branch -D <branch name> 强制删除指定分支
10 $git merge master 将master分支与当前分支合并
11 $git merge master <branch> 将master分支与指定分支合并
11 $git branch -m <old name> <new name> 修改分支名
12 $git checkout -b <new branch name> origin/<remote branch name> 拷贝远端指定分支到本地新建的分支
13 $git --bare init 在本地初始化代码库
14 $git checkout origin/xxx 切换到指定xxx的远程分支
15 $git branch -vv 查看本地分支与远端分支的映射联系
16 $git branch -u origin/xxx 将本地分支与指定远端分支建立联系
Num Command Description
1 $git add <filename> 将更改的文件加入到Stage中缓存
2 $git commit <filename> 将缓存在Stage中的文件提交到本地仓库Repo中
3 $git commit -m <descriptions> 将缓存在Stage中的文件提交到本地仓库Repo中,并加入更新的描述信息
4 $git checkout -- <filename> 撤销未使用git add <filename>加入Stage的更改操作
Num Command Description
1 $git log 查看日志
2 $git log --graph 以“图形”化显示日志
3 $git reseet --hard HEAD^ 回滚至上一次commit
4 $git reseet --hard HEAD~n 回滚至上n次commit
5 $git reseet --hard <commit hash code> 回滚至指定commit哈希码对应的提交
6 $git reflog 查看回滚日志
7 $git reset --hard HEAD@{n} 恢复至回滚日志中的指定状态
8 $git reset --soft HEAD^ 回滚至上一次commit,并将更改缓存至Stage中
9 $git revert <commit hash code> 将该次提交作出的修改回退
10 $git checkout <commit id> <path> <path>回退至<commit id>版本
Num Command Description
1 $git pull 将远程代码库更新至本地代码库
1 $git pull <origin name> <branch> 将远程代码库指定分支更新至本地代码库分支
2 $git push origin <branch> 将本地代码库的branch分支推送至origin远程代码库的branch分支
3 $git diff 查看Workspace与Stage中文件的区别
4 $git diff <commit hashcode> 查看Workspace与指定commit的区别
5 $git diff <commit hashcode> <commit hashcode> 查看指定的两次提交的区别
6 $git diff HEAD^ 查看Workspace与上一次提交的区别
7 git branch -d <origin/branch>
git push origin :<branch>
删除远端分支
8 $git push origin 若本地分支已与远端分支相关联,则可省略参数推送
9 $git push origin HEAD:refs/for/master 提交代码,并添加评审
10 $git diff --cached <commit id> 查看本地已经commit的内容
11 git rebase -i HEAD~${i} rebase,并修改前 i 次的提交日志(根据弹出框提示信息继续操作)
Num Command Description
1 $git log --stat 显示每次提交文件大小变化
2 $git log --stat <filename> 显示指定文件的文件大小变化
3 $git log --graph 显示每次提交的轨道图
上一篇 下一篇

猜你喜欢

热点阅读