git简单总结(二)版本操作相关

一、git 版本的回退

    1. git log 查看当前git 仓库提交的版本记录.
      git 的版本号"8e9c215524339c5305679660fead427136636a9b"是一个md5 后的密文
sc:TestGit yang$ git log
commit 8e9c215524339c5305679660fead427136636a9b
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:23:10 2017 +0800
第四次提交代码

commit 50e971dc6a5239efb335e1b2c802e177a4c4e43c
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:22:39 2017 +0800
第三次提交代码

commit 041f195c6045b831c26be65a353f3dfbca52ca96
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:22:01 2017 +0800
第二次提交代码

commit ca0cf6173f0ceac471fab12c38463ed874b4b8dd
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:21:09 2017 +0800
第一次提交代码
    1. git reset --hard HEAD^ 回退到最近提交的前一个版本
      git reset --hard HEAD^^ 回退到最近提交的前一个的前一个版本
sc:TestGit yang$ git reset --hard HEAD^
HEAD is now at 50e971d
 第三次提交代码

sc:TestGit yang$ git log
commit 50e971dc6a5239efb335e1b2c802e177a4c4e43c
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:22:39 2017 +0800
第三次提交代码

commit 041f195c6045b831c26be65a353f3dfbca52ca96
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:22:01 2017 +0800
第二次提交代码

commit ca0cf6173f0ceac471fab12c38463ed874b4b8dd
Author: mango <690852195@qq.com>
Date:   Sun Dec 31 21:21:09 2017 +0800
第一次提交代码
    1. git reflog 查看git仓库的历史版本记录(包含之前回退的版本号也可以看见)
sc:TestGit yang$ git reflog
50e971d HEAD@{0}: reset: moving to HEAD^
8e9c215 HEAD@{1}: commit: 第四次提交代码
50e971d HEAD@{2}: commit: 第三次提交代码
041f195 HEAD@{3}: commit: 第二次提交代码
ca0cf61 HEAD@{4}: commit (initial): 第一次提交代码
    1. git reset --hard 版本号 ,回退的指定版本后(甚至可以是上次删除的版本,只要是通过 git log 或则 git reflog 能查到的版本号)
sc:TestGit yang$ git reflog
50e971d HEAD@{0}: reset: moving to HEAD^
8e9c215 HEAD@{1}: commit: 第四次提交代码
50e971d HEAD@{2}: commit: 第三次提交代码
041f195 HEAD@{3}: commit: 第二次提交代码
ca0cf61 HEAD@{4}: commit (initial): 第一次提交代码

sc:TestGit yang$ git reset --hard HEAD^
HEAD is now at 041f195 第二次提交代码

sc:TestGit yang$ git reset --hard 8e9c215
HEAD is now at 8e9c215 第四次提交代码
sc:TestGit yang$ 

二、git 文件的删除

    1. git rm 文件路径 (删除文件)
sc:TestGit yang$ git rm ViewController.h
fatal: pathspec 'ViewController.h' did not match any files

sc:TestGit yang$ git rm TestGit/ViewController.h rm 'TestGit/ViewController.h'

sc:TestGit yang$ git status  

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    TestGit/ViewController.h

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   TestGit.xcodeproj/project.xcworkspace/xcuserdata/yang.xcuserdatad/UserInterfaceState.xcuserstate

三、git branch 分支

    1. git branch 查看git 的所有的分支分支
sc:TestGit yang$ git branch 
* master
    1. git branch v1.0 从当前的分支创建一个新的分支(v1.0 是新创建的分支名称)
sc:TestGit yang$ git branch 
* master

sc:TestGit yang$ git branch v1.0
sc:TestGit yang$ git branch
* master   // * 表示当前正在执行的分支
  v1.0
    1. git check v1.0 切换分支 (v1.0 要切换的分支名称)
sc:TestGit yang$ git branch
* master
  v1.0
  v2.0

sc:TestGit yang$ git checkout v1.0
Switched to branch 'v1.0'

sc:TestGit yang$ git branch
  master
* v1.0   // * 表示当前正在执行的分支
  v2.0
    1. git merge 合并分支
sc:TestGit yang$ git merge v2.0
Already up-to-date.
    1. git branch -d v1.0 删除分支(v1.0 将要删除的分支的名称)
sc:TestGit yang$ git branch
  master
* v1.0
  v2.0

sc:TestGit yang$ 
sc:TestGit yang$ 
sc:TestGit yang$ git branch -d v2.0
Deleted branch v2.0 (was 8e9c215).

sc:TestGit yang$ git branch 
  master
* v1.0

说明: git branch -d v1.0 不能删除当前正在执行的分支,如果要删除当前的分支,请先切换出当前分支在移除.

Git 简单总结(一) https://www.jianshu.com/p/4a63323fc55b

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • git常用命令 GIT常用命令备忘:http://stormzhang.com/git/2014/01/27/gi...
    新篇章阅读 8,887评论 1 26
  • 1.git的安装 1.1 在Windows上安装Git msysgit是Windows版的Git,从https:/...
    落魂灬阅读 12,848评论 4 54
  • 2017年2月24日,网友发现网上所有韩国综艺的2017年新视频都无法播放,疑似落实“限韩令”。 对,这就是今天的...
    Zero杂谈阅读 259评论 0 0
  • 学习的本质就是认识你自己! 我本身是一个非常拒绝学习的人!我仔细分析了一下原因:①高中的学习经历实在是太痛苦了,高...
    007Perryly阅读 433评论 0 2
  • 《2013年的十个好想法》epub下载地址《2013年的十个好想法》多看下载地址《2013年的十个好想法》豆瓣阅读...
    简书阅读 1,331评论 4 12

友情链接更多精彩内容