Git 版本控制 -- 理解 Git Rebase 指令

git reset 使用场景为丢弃 commit 后的 commit信息、index 信息或者源码。

git reset 三种模式

 - -soft
 - -mixed(默认)
 - -hard

git reset - -soft HEAD~n或commit id

回退项: commit 信息
回退情况: 当前 commit 与目标 commit 信息之间的 commit 信息丢失,此时index 信息未发生改变 ,此时的状态为 —- stage 状态后未 commit 的状态,执行 git commit 将本次操作提交到本地分支。

git reset (- -mixed)HEAD~n或commit id

回退项: index 信息 (暂存区信息)、commit 信息
回退情况: 当前 commit 与目标 commit 信息之间的 commit 信息丢失,此时index 信息也发生改变,此时的状态为 —- unstage状态,需执行git add . 将文件变更暂存,执行git commit将本次操作提交到本地分支。

git reset - -hard HEAD~n或commit id

回退项: index 信息、commit信息、源码
回退情况: 当前 commit 与目标 commit 信息之间的 commit信息、index信息、源码全部丢失。

此时如果想把现在的代码块提交到远端,使用以下命令:

git push origin HEAD --force

注意,此命令会使远端代码也进行回退,慎用。

git reset 使用

git reset [模式] commit Id

使用指令 git reflog 查看操作历史,定位想要恢复的 commit Id
根据情况执行 git reset commitId
一般恢复为源码恢复,其他两种模式没有恢复的价值(个人认为),所以一般的执行为git reset –hard commit Id

猜你喜欢

转载自blog.csdn.net/Strange_Monkey/article/details/82689601