git 常用命令整理
目的为了自己查找方便,也为大家提供便捷
| 命令 | 说明 |
|---|---|
| git init | 初始化git仓库 |
| git status | 查看工作区状态 |
| git diff filename git diff --cached filename git diff --filename | 比较工作区和暂存区 比较暂存区和版本库 比较工作区和版本库区别 |
| git add fileName git add | 添加文件到暂存区,配合git commit使用 |
| git commit -m “comment” | 提交代码到版本库 |
| git log git log --pretty=oneline git log --graph --pretty=oneline --abbrev-commit | 查看git修改提交记录 |
| git reflog | 记录每一个git的操作命令 |
| git reset --hard HEAD git reset --hard HEAD^ git reset --hard HEAD~100 git reset --hard commit id | 退回版本 退回上一版本 退回前100个版本 退回指定commit id版本 |
| git reset HEAD filename | 撤销暂存区修改 |
| git checkout – filename | 把filename在工作区修改内容还原(git commit/git add)状态 |
| git rm filename | 删除版本库文件 |
| ssh-keygen -t rsa -C "youremail@example.com" | 创建SSHKEY |
| git remote add origin git@github.com:xxx/xxx.git | 本地版本库关联远程版本库 |
| git clone git@github.com:xxx/xxx.git | 从远程克隆版本库到本地 |
| git push -u origin master git push origin master | 推送本地版本库到远程版本库 -u:关联本地master和远程master |
| git remote -v | 查看远程库信息,-v:显示详细信息 |
| git branch --set-upstream-to branchname origin/branchname | 连接本地分支和远程分支 |
| git branch branchname | 创建分支 |
| git checkout branchname | 切换到指定branchname下 |
| git checkout -b branchname | 创建分支并且换到创建分支下面 |
| git branch | 查看分支列表,*代表当前分支 |
| git merge branchname git merge --no-ff -m “comment” branchname | 把branchname合并到当前分支 合并分支并记录合并信息 |
| git branch -d branchname | 删除branchname |
| git stash | 存储当前现场,说白了就是保护 |
| git stash list | 查看存储现场列表 |
| git stash apply git stash apply stash@{0} | 恢复现场,不删除stash内容 |
| git stash drop | 删除stash内容,一般配合git stash apply使用 |
| git stash pop | 恢复现场,同时删除stash内容 |
Git常用命令整理

552

被折叠的 条评论
为什么被折叠?



