回退到指定版本

来自StackOverflow的一个精彩回答:https://stackoverflow.com/a/36177806

1. 获取当前分支名

# git branch
* master

2. 获取要回滚到的版本

# git log

3. 将远程回退到指定版本

# git push -f origin f18857fb2edac9ea2e4e89794844fd8310b12971:master
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:aiplatform/test.git
 + 65a6eaa...f18857f f18857fb2edac9ea2e4e89794844fd8310b12971 -> master (forced update)

4. 检查本地仓库状态

# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

这是表明你超前仓库一次提交,所以接下来回滚本地版本

5. 将本地回退到指定版本

# git reset --hard f18857fb2edac9ea2e4e89794844fd8310b12971
HEAD is now at f18857f blabla

6. 检查最终本地和远程状态

# git log

results matching ""

    No results matching ""