Git 回滚到某一版本 指定commit号

前期准备工作

git log 查看你想回滚到的版本的commit号

开始

回滚的奥义就是使用git reset

从git文档中可以看到

git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

在使用的时候,可以使用

git reset --soft 8ff24a6803173208f3e606e32dfcf82db9ac84d8

git reset --hard XXX

git reset [DESCRIPTION-option]  [<commit>]

由于我只用过 soft 和 hard,记录下这两个(其实还不是因为懒……

  1. soft(轻柔)你懂得,说明 git 只会把 HEAD头指向你指定的commit号,但是不会改变索引文件或者工作树中的内容,这个命令会让所有的更改文件保持在 “Changes to be committed” (等待提交的状态)
    1. 大白话:你在项目中的更改会被保留
  2. hard(强硬),重置索引和工作树。你在项目所有的更改没会都没有,所以慎用hard选项……不然你会一脸懵逼+震惊的“卧槽,我代码咋没了?!!”

  3. mixed(混合)会重置索引,但是不重置工作树。所做更改,未追踪的文件(在工作树里边的)会被保留。git的默认选项

如果你觉得这三种都不满足你的需求,那么去看git文档的吧!我真是懒得翻译了……

--merge

Resets the index and updates the files in the working tree that are different between and `HEAD`, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between and the index has unstaged changes, reset is aborted.

In other words, --merge does something like a git read-tree -u -m, but carries forward unmerged index entries.

--keep

Resets index entries and updates files in the working tree that are different between and `HEAD`. If a file that is different between and HEAD has local changes, reset is aborted.

背景

今天为啥写这个呢?因为项目里边用了git submodule,是真的坑,初入手的人,真的会让搞得一脸蒙圈。

其他同事在product中push的时候,把上一位的commit内容给覆盖了。这坑爹的原因我竟然还没找到。

按理来说,在push时,一定会让git pull的。pull完合到本地dev时,肯定会更新或者冲突啊。但是TNND真的神奇,就带个上上上上上个的commit就给push上来了。这特么的什么神奇小饼干?问题老版本里的package.json包名写错了,会起不来项目,这个锅又到了我头上。大人,我冤枉啊……

现在的解决方案两个:

  1. 回滚到之前对的。让错误提交的重新commit一遍
  2. 继续这个坏的。我本地再次改完,重新push一遍

made,一个我都不想选……

Over

猜你喜欢

转载自www.cnblogs.com/xyJen/p/12467889.html
今日推荐