我是一个新手,对于git还不太熟悉,所以在做任何不可恢复的错误之前都会先询问... :-)
最近几天,我对项目进行了一些更改,以升级我使用的一些库的版本,但我失败了(也因为文档不足... :-()。
我只好放弃升级,现在需要回滚到上一个稳定提交。
我也已经推送到远程,但这不应该是问题,因为我目前是该项目唯一的开发者。
以下是我的当前git日志:
我遇到了这个错误:
最近几天,我对项目进行了一些更改,以升级我使用的一些库的版本,但我失败了(也因为文档不足... :-()。
我只好放弃升级,现在需要回滚到上一个稳定提交。
我也已经推送到远程,但这不应该是问题,因为我目前是该项目唯一的开发者。
以下是我的当前git日志:
$ git log --oneline
22c0713 Upgrading to Firebase 1.1
6d5f9f4 Porting customers to angularfire 0.8
fd9db42 Porting to Angularfire 0.8
d728b82 Working out authenticating on authenticated session problems
d511245 Testing authWithOAuthRedirect
abd9849 Porting to firebase 1.1.2
8884b88 Testing loadRemote() with relative path on public repositories
7830eea Testing loadRemote() with relative path on public repositories
f36c2f5 Finished working on I18N
...
f36c2f5提交(上面我展示的最后一个)是最后一个稳定版本,我想要恢复到那个版本。
我还想避免丢失新的(不好的)提交,以备未来参考。
针对此任务,哪种策略最为可取?
更新:多谢您的回答,我差不多完成了(待会就要接受答案了……)。只有一个小问题:我也有一个“gh-pages”分支,用于将我的dist子文件夹推送到GitHub的gh-pages预备站点。
现在,在
git checkout -b my_branch_for_future_reference
git checkout master
git reset --hard f36c2f5
git push -f
进行中
git subtree push --prefix dist origin gh-pages
我遇到了这个错误:
git push using: origin gh-pages
To git@github.com:MYUSER/MYREPO.git
! [rejected] 3febf7c0812441c7379710d0a1f5f1ec26adbd9e -> gh-pages (non-fast-forward)
error: failed to push some refs to 'git@github.com:MYUSER/MYREPO.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我查了一下,但是git subtree push没有'-f'标志... :-(
更新2: 我想我自己找到了上一个问题的答案:
git push origin `git subtree split --prefix dist master`:gh-pages --force
可能是解决方案,对吧?(我还没有运行它...:-))
更新3:是的,这就是强制推送子树的解决方案。
git branch
命令创建一个新分支而不进行检出。 - Rich