我正在和一个合作者一起做一个项目,我们俩都不擅长GitHub。项目在这里。他推动了一个我基本上不想要的承诺。我希望我的承诺成为头。显然,两个文件中存在一些冲突,我什至无法弄清楚它们在哪里。 我试过了git reset --hard b8b0907bc259f245ff039805179b943763ddb5d9
这确实将我的本地存储库恢复为我想要的提交。但它不会让我推动它,因为它说我当地的分支机构落后了:
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.
这将完成您的要求:
git stash # in case you have any unsaved changes
git fetch # update your local repo with what's in remote origin
git checkout blais_replication # move HEAD to this branch
git reset --hard b8b0907bc259f2 # set branch to that commit (7b1aee is now "lost")
git push --force # make remote origin like how your repo is
请注意,这将有效地"改变历史记录",使其好像从未提交过7b1aee
。由于历史记录更改,其他用户将看到同步问题。他们可以运行:
git checkout blais_replication
git fetch # update local repo
git reset --hard origin/blais_replication # moves branch to where origin/blais_replication has been moved back to (b8b0907bc259f2)