Git常用命令——分支操作
Git常用命令——分支操作
分支操作
git branch 列出,创建或者删除分支
- git branch <branchName> :创建一个分支
- git branch -d <branchName> :删除指定分支
- git branch -v :显示现在的所有分支信息
* master 4757e41 full commit
next 4757e41 full commit
* 4757e41 full commit
* 53a1a79 initial commit
4757e417cb400c7cb6a45985ec5317fd51efaba4
master next
[master 32dd26e] three commit
1 file changed, 1 insertion(+)
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 32dd26e three commit
* 4757e41 full commit
* master 32dd26e three commit
next 4757e41 full commit
git checkout(补充:对于内容来说,该操作是检出版本,本质上只是移动head指针)
- git checkout <branchName> :将head指针指向目标分支
- git checkout -b <branchName> :创建该分支,并将head指针指向它
- git checkout <reference> :将head指针移动到任何引用对象上
- git checkout - :恢复到上一个head指向的分支
Switched to branch 'next'
* next 31397de next four commit
SwitchdeMacBook-Pro:git-tutorial switch$ cat README.md
Read me
[next 31397de] next four commit
1 file changed, 1 insertion(+)
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 31397de next four commit
* 4757e41 full commit
* 53a1a79 initial commit
Switched to branch 'master'
SwitchdeMacBook-Pro:git-tutorial switch$ git branch -v
* master 32dd26e three commit
next 31397de next four commit
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 32dd26e three commit
* 4757e41 full commit
* 53a1a79 initial commit
Switched to a new branch 'issue1'
SwitchdeMacBook-Pro:git-tutorial switch$ git branch -v
* issue1 32dd26e three commit
master 32dd26e three commit
next 31397de next four commit
* 32dd26e three commit
* 4757e41 full commit
* 53a1a79 initial commit
SwitchdeMacBook-Pro:git-tutorial switch$ git checkout 4757e41
Note: checking out '4757e41'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 4757e41... full commit
SwitchdeMacBook-Pro:git-tutorial switch$ git branch -v
* (HEAD detached at 4757e41) 4757e41 full commit
issue1 32dd26e three commit
master 32dd26e three commit
next 31397de next four commit
git reset(补充:将当前分支回退到历史某个版本)
- git reset --mixed <commit> (默认):内容复制回暂存区
- git reset --soft <commit>:内容区和暂存区保存原有状态
- git reset --hard<commit>:内容复制回工作区和暂存区
- git reset <branchName>^:回退到branchName的父提交
- git reset <branchName>~n:回退到branchName前的第n次提交
git reflog(按从新到旧的顺序,记录head访问提交的记录)
4757e41 HEAD@{0}: checkout: moving from issue1 to 4757e41
32dd26e HEAD@{1}: checkout: moving from master to issue1
32dd26e HEAD@{2}: checkout: moving from next to master
31397de HEAD@{3}: commit: next four commit
4757e41 HEAD@{4}: checkout: moving from master to next
32dd26e HEAD@{5}: commit: three commit
4757e41 HEAD@{6}: commit: full commit
53a1a79 HEAD@{7}: commit (initial): initial commit
git stash(保存目前的工作目录和暂存区状态,并返回到干净的工作空间)
- git stash save ‘message’ :压入stash区栈顶
- git stash list :列出stash区的元素
- git stash apply stash编号 :将stash栈中对应编号的对应的状态返回给工作区
- git stash drop stash编号 :删除stash栈中对应编号的状态
- git stash pop :等价于 stash apply 栈顶元素+ stash drop 栈顶元素
git merge(合并分支)
- git merge branchName1 branchName2 :将分支1合并到分支2
- git merge branchName :将branchName合并到当前分支
- git merge branchName —ff :将branchName合并到当前分支,使用fast-forward方式
- fast-forward(快速向前合并)的形式是,两个分支,有一个并未有提交记录。
- git merge branchName --no-ff :将branchName合并到当前分支,不使用fast-forward方式
issue1 32dd26e three commit
* master 32dd26e three commit
next 101fda8 next five
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 32dd26e three commit
* 4757e41 full commit
* 53a1a79 initial commit
SwitchdeMacBook-Pro:git-tutorial switch$ git checkout -
Switched to branch 'next'
SwitchdeMacBook-Pro:git-tutorial switch$ git branch -v
issue1 32dd26e three commit
master 32dd26e three commit
* next 101fda8 next five
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 101fda8 next five
* 31397de next four commit
* 4757e41 full commit
* 53a1a79 initial commit
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
SwitchdeMacBook-Pro:git-tutorial switch$ git commit -a -m 'resolve'
[master 56fdf65] resolve
SwitchdeMacBook-Pro:git-tutorial switch$ git log --graph --oneline
* 56fdf65 resolve
|\
| * 101fda8 next five
| * 31397de next four commit
* | 32dd26e three commit
|/
* 4757e41 full commit
* 53a1a79 initial commit
git cat-file(查看git仓库中对象的信息)
- git cat-file -p head :打印head指向提交对象的信息
tree 3c221ae1529d61605e394447da6972633bb27041
parent 32dd26e684a88b58a692872d4f21ddb1fa23a3af
parent 101fda89564e18e4583105fbd647c87249917fdc
author switch <q547550831@outlook.com> 1471768711 +0800
committer switch <q547550831@outlook.com> 1471768711 +0800
resolve
git rebase(修剪提交历史基线,变基)
- git rebase master :将head所指向的分支在master分支上重演。
- git rebase --onto master 5751363 :将5751363后的提交在master上重演。
git tag(对某个提交设置一个不变的别名)
- git tag tagName 提交对象Sha1值 :对对应提交对象设置一个别名
Note: checking out 'nfc'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 31397de... next four commit
initcom nfc
-------------参考《网易云课堂.Java Web开发入门》
Git常用命令——分支操作相关推荐
- Git常用命令——远程操作
Git常用命令--远程操作 远程操作 先不引入github,利用git支持本地协议的特性,创建一个本地的远程服务器. 创建一个裸仓库(没有工作目录) SwitchdeMacBook-Pro:git-s ...
- Git详细用法:Git概述 安装 常用命令 分支操作 团队协作 、GitHub、idea集成Git、idea集成GitHub、Gitee 码云、GitLab
0 课程介绍 说明: 在公司想要使用idea集成git: 首选需要下载安装Git(查看第2章) 之后在中设置用户签名(查看3.1) 然后在idea中集成Git(查看第7章) - 0.1 学习目标 第1 ...
- git常用命令,分支操作,子模块
Git 是一个很强大的分布式版本管理工具,它不但适用于管理大型开源软件的源代码(如:linux kernel),管理私人的文档和源代码也有很多优势(如:wsi-lgame-pro) 二. Git 常用 ...
- Git之(三)Git中常用命令——分支管理
三.Git中常用命令--分支管理 为什么要使用分支管理? 分支就是科幻电影里面的平行宇宙,也就是当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干 ...
- Git 常用命令操作详解
Git常用命令 Git提供了很多命令来完成相应的操作,为了方便学习,我们将这些命令进行了分类.在学习命令的过程中会讲解一些Git相关的概念. 在本章节我们会学习到如下一些命令和概念: 环境配置 获取G ...
- Git的使用——Git 常用命令总结、Git的使用、Git 的分支、远程仓库的使用、IDEA 中使用Git、Git 工作流(Git Flow、Github Flow、GitLab Flow)
Git的使用--Git 常用命令总结.Git的使用.Git 的分支.远程仓库的使用.IDEA 中使用Git 一.Git 常用命令总结 为了方便后续查找命令,故先把总结放前面,教程放后面 1.git 基 ...
- git切换分支及关联远程仓git常用命令。
本地拉取新分支并关联个人远程仓步骤: 步骤一: 1.1先切本地分支 git checkout 分支名称(切换分支) 1.2或创建分支 git branch 分支名称(需要先拉主分支代码) 1.3或创建 ...
- 【转载】Git 常用命令大全
一. Git 常用命令速查 git branch 查看本地所有分支 git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支 git branch ...
- Git 常用命令集锦
文档已储存在 GitHub,这里不再更新校正,请原谅. 远程仓库相关命令 克隆远程仓库:git clone git://github.com/jquery/jquery.git 查看远程仓库:git ...
最新文章
- 破除SCI至上!评价 AI 科研成果,需要新思路【附报告下载】
- python搞笑代码-为PYTHON添加define功能【搞笑代码】
- 050_整形和字节数组转换
- JVM中的栈和局部变量
- 这文字的起始位置_ae制作文字动画?ae文字动画教程
- 剑指-顺时针打印矩阵
- Unity MeshBaker 合并网格和材质
- mysql linux设置密码_Linux下第一次使用MySQL数据库,设置密码
- Sqlit--学习教程(基本操作1)
- 95-240-060-源码-state-状态生存时间(TTL)
- java statement 存储过程_Java+sql server+CallableStatement调用存储过程三种情况 (转)...
- 省市区三级联动菜单(附数据库)
- 简易高重用的jdbcutils工具封装实现类以及简易连接池实现
- phpstrom中的常用快捷键
- 空气质量等级c语言编程,字节跳动2018秋招编程题——空气质量
- 慕课静态页面制作周记
- java输出hello word,新手求教如何输出helloword
- misc.imresize
- 用WinDbg分析电脑蓝屏文件
- 字符串数据处理 arduino