Git常用命令
来源:互联网 发布:arm linux入门 编辑:程序博客网 时间:2024/06/06 09:25
查看、添加、提交、删除、找回,重置修改文件
git help <command> # 显示command的help
git add <file> # 将工作文件修改提交到本地暂存区
git add . | git add --all # 将所有修改过的工作文件提交暂存区
git rm <file> # 从版本库中删除文件
git rm <file> --cached # 从版本库中删除文件,但不删除文件
git reset <file> # 从暂存区恢复到工作文件
git reset -- . # 从暂存区恢复到工作文件
git reset --hard # 恢复最近一次提交过的状态,即放弃上次提交后的所有本次修改
git ci --amend # 修改最后一次提交记录
git revert <$id> # 恢复某次提交的状态,恢复动作本身也创建次提交对象
git revert HEAD # 恢复最后一次提交的状态
查看文件diff
git diff <
git diff <branch1>..<branch2> # 在两个分支之间比较
查看提交记录
git log | git log <file> # 查看该文件每次提交记录
git log -p <file> # 查看每次详细修改内容的diff
git log -p -2 # 查看最近两次详细修改内容的diff
Git 本地分支管理
查看、切换、创建和删除分支
git branch -r # 查看远程分支
git branch <new_branch> # 创建新的分支
git branch -v # 查看各个分支最后提交信息
git branch r --merged # 查看已经被合并到当前分支的分支
git branch --no-merged # 查看尚未被合并到当前分支的分支
git branch <branch> # 切换到某个分支
git branch -b <new_branch> # 创建新的分支,并且切换过去
git branch -b <new_branch> <branch> # 基于branch创建新的new_branch
git branch $id -b <new_branch> # 把某次历史提交记录checkout出来,创建成一个分支
git branch -d <branch> # 删除某个分支
git branch -D <branch> # 强制删除某个分支 (未被合并的分支被删除的时候需要强制)
Git分支合并和rebase
git merge <branch> # 将branch分支合并到当前分支
git merge origin/master --no-ff # 不要Fast-Foward合并,这样可以生成merge提交
Git暂存管理
git stash # 暂存
git stash list # 列所有stash
git stash apply # 恢复暂存的内容
git stash drop # 删除暂存区
Git远程分支管理
git checkout -b [name] # 创建新分支并立即切换到新分支
git pull # 抓取远程仓库所有分支更新并合并到本地
git pull --no-ff # 抓取远程仓库所有分支更新并合并到本地,不要快进合并
git fetch origin # 抓取远程仓库更新
git merge origin/master # 将远程主分支合并到本地当前分支
git co --track origin/branch # 跟踪某个远程分支创建相应的本地分支
git co -b <local_branch> origin/<remote_branch> # 基于远程分支创建本地分支,功能同上
git push # push所有分支
git push origin master # 将本地主分支推到远程主分支
git push -u origin master # 将本地主分支推到远程(如无远程主分支则创建,用于初始化远程仓库)
git push origin <local_branch> # 创建远程分支, origin是远程仓库名
git push origin <local_branch>:<remote_branch> # 创建远程分支
git push origin :<remote_branch> #先删除本地分支(git br -d <branch>),然后再push删除远程分支
Git远程仓库管理
GitHub
git remote -v # 查看远程服务器地址和仓库名称
git remote show origin # 查看远程服务器仓库状态
git remote add origin git@ github:robbin/robbin_site.git # 添加远程仓库地址
git remote set-url origin git@ github.com:robbin/robbin_site.git # 设置远程仓库地址(用于修改远程仓库地址) git remote rm <repository> # 删除远程仓库
- git 常用命令
- Git常用命令
- git 常用命令
- git 常用命令
- git 常用命令
- git 常用命令
- GIT常用命令
- git 常用命令
- git 常用命令
- Git 常用命令
- git 常用命令
- Git常用命令
- Git常用命令
- git 常用命令
- Git 常用命令
- git常用命令
- git 常用命令
- Git 常用命令
- Android Studio检测没有用到的资源
- Hashtable与ConcurrentHashMap区别
- 简单工厂模式
- 【5.20_专辑】来聊聊程序猿的那些花式表白
- 阿里云 CentOS LNMP 环境搭建
- Git常用命令
- C++循环
- HDU 2602 Bone Collector——01背包
- 自己安装mysql的一系列问题的最终解决方法-----解压缩安装
- 记一次VB Windows程序的启动和退出处理
- 几种P2P流媒体开源项目介绍
- Oracle嵌套表简介
- cocos2dx_js调用本地摄像头及相册
- 浅谈java集合中线程安全的类