如何进行版本回退

回滚ci#

直接回滚ci,但是main分支的代码不会修改

reset#

git reset 会把版本回退到某一个 Head~

然后我们要了解三个区

工作目录 暂存区(Index) HEAD
本地的代码区域 add加入的地方 commit后的地方

然后 reset 有三个模式

  • --soft

    Files won’t change, differences will be staged for commit.

  • --mixed

    Files won’t change, differences won’t be staged,

  • --hard

    Files will be reverted to the state of the selected commit.

其实从英语的意思上就可以看出,越严格撤回的越多

1
2
3
4
git reset --mixed <commit-id>
git reset --mixed <branch-name>
git reset --mixed <tag-name>
git reset --mixed HEAD~<n>

这个命令虽然可以直接撤销我们提交的代码,但是有个问题就是他会直接销毁我们的commit,导致我们回溯到的节点之后都没有commit节点了

UI:

image-20241205233748482

image-20241205233807264

revert#

直接会在最新的commit后面新加一个 Revert "feat: xxx"commit,表示该commit被逆转了,如果想要逆转回来只要对刚才逆转的Revert "feat: xxx"再进行一遍revert即可

UI:

image-20241205234234255

总结来说就是 goland 里面第一下就行