0

git status给了我这个:

您的分支在 11 次提交之后位于“来源/网络”之后,并且可以快速转发。

这是因为我重置为较早的版本(希望放弃我之后所做的一切)。

但是,如果我尝试推送该版本(或该版本进行了一些小的更改),这将不起作用。我不想要新的东西,我只想从我恢复到的旧版本开始新的!

我该怎么办?

4

2 回答 2

3

如果你是仓库的唯一用户,可以强制推送;但是如果其他人从回购中撤出,你不应该强制推送,因为它会弄乱其他人的历史。

你可以git merge --ff-only origin/network然后git revert HEAD~11或类似的东西来生成一个新的提交,撤销过去的十一次提交,而不改变提交历史。

另请参阅对类似问题的回答

于 2013-01-11T07:48:08.103 回答
2

Since you've already pushed the "future" code, you want to avoid rewriting history at all costs if you have other contributors. You would introduce pretty severe updating nightmares.

If you know that nobody else has pulled the newest code, you can do the following to "recreate" the branch at a specific point. The following rewrites the history of your network branch.

git reset --hard <commit-id>
git push --force origin network

If you don't want to rewrite history (you should always avoid rewriting push-ed history), you can 'revert' the last 11 commits on the network branch. The following is done while on the HEAD of your network branch.

git revert OLDER_COMMIT^..NEWER_COMMIT

This effectively creates commits which 'revert' existing commits. Though where you might find yourself in trouble on this is if you merge this branch into another branch later and wanted to preserve your existing 11 commits for the merged branch. See: the answer for Revert Multiple git commits.

You could also revert the 11 commits in one commit.

# reset your network branch to be the same as the remote
git reset --hard origin/network

# Set your branch (soft) index to the commit point you want your branch state to have:
git reset --soft <commit-id>

# The index will change and the files will reflect a difference you can now commit:
git commit -a
于 2013-01-11T08:41:18.037 回答