Your branch is ahead of ‘origin/master‘ by 2 commits. (use “git push“ to publish your local commit

遇到问题:

Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

首先一定要自己手动备份一份代码 防止意外


这个消息表示你的本地分支比远程仓库的 master 分支超前了2个提交。这通常发生在你在本地进行了一些提交,但还没有将这些提交推送到远程仓库。

我选择撤回之前的两次提交(具体次数根据实际情况)

首先在git bash中使用git log命令查看最近的提交情况

 我想要恢复到5-7这个版本

所以我使用git reset --hard HEAD~2 回溯到两次提交之前

 

 此时如图

再次查看log,发现已经恢复到之前版本

猜你喜欢

转载自blog.csdn.net/qq_53873381/article/details/131362061