我们需要回到特定的提交记录。一些意外更改已经被合并到了主分支上,试图还原这些更改会导致问题进一步加剧,因此我们需要将主分支恢复到 66ada4cc61d62afc 提交记录。
根据 git revert back to certain commit:
$ git reset --hard 66ada4cc61d62afc
HEAD is now at 66ada4c Updated documentation
接着,尝试提交它:
$ git add *.h *.cpp
$ git commit -m "Go back to Commit 66ada4cc61d62afc"
On branch master
Your branch is behind 'origin/master' by 16 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean
最后:
$ git push
To https://github.com/weidai11/cryptopp.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/weidai11/cryptopp.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
现在,一切都恰到好处。我不知道为什么Git出了问题,也不知道Git在说什么。如果Git能按照指示执行就太好了。但不幸的是,Git使每个简单的任务都变得困难,并会带来不必要的痛苦和折磨。
我该如何提交并推送更改?
git checkout 66ada4cc61d62afc .; git add .; git commit -m "foo"
命令。git checkout version
告诉你当前处于分离头状态,git checkout version filename
可以从历史记录中获取文件。 - Robin Rothgit checkout <hash> .
不会删除文件。更安全的方法是git checkout <hash> && git reset --soft master && git commit
。 - poke