0

这是我的 Git 状态。

在此处输入图像描述

因为一些奇怪的原因,master树枝task-e被折断了。他们现在无法建造。
只有6f374ed94ad7f04b1f7a2ca2019374bb7785d9e6提交是有效的。 在此处输入图像描述

我想将此提交提交到master分支的最新提交。我该怎么办?

4

2 回答 2

1

It's not completely clear from your question, but I assume that what you want is to add a new commit whose source code is exactly the same as at the older commit, 6f374ed9. (In other words, you want to avoid rewriting history, since obviously master and task-e have been pushed to GitHub.) This takes a few steps in git, which are described in this question. To summarize that, firstly make sure that you have no uncommitted changes (i.e. git status is clean). You would then need to do:

# Switch to the branch you want to add the commit to:
git checkout master
# (... you can merge the result to the other branch later)

# Move the master branch back to the earlier, good commit, forcing the
# working tree and the index to match:
git reset --hard 6f374ed

# Use git reset --soft to point the master branch back to where it was
# originally, but leave the working tree and index as they were at 6f374ed
git reset --soft HEAD@{1}

# Commit the result:
git commit -m "Reverting state back to 6f374ed9"

Then, to update task-e as well, you can do:

git checkout task-e
git merge master
于 2012-07-13T09:11:48.667 回答
0

您可以使用git reset,但它会重写已公开推送的历史记录,因此不建议这样做。我会使用git revert: 它允许您恢复提交,即。它创建一个与提交相反的提交。这样,您可以取消提交并返回到您想要的状态,而无需重写历史记录。

于 2012-07-13T08:57:34.827 回答