這是我的Git狀態。如何使舊的提交對象變爲最新的?
由於一些奇怪的原因,master
和task-e
樹枝都折斷了。他們現在不能建造。
只有6f374ed94ad7f04b1f7a2ca2019374bb7785d9e6
提交有效。
我想使此承諾最遲落入master
分支。我該怎麼做?
這是我的Git狀態。如何使舊的提交對象變爲最新的?
由於一些奇怪的原因,master
和task-e
樹枝都折斷了。他們現在不能建造。
只有6f374ed94ad7f04b1f7a2ca2019374bb7785d9e6
提交有效。
我想使此承諾最遲落入master
分支。我該怎麼做?
從你的問題來看,這並不完全清楚,但我認爲你想要的是添加一個新的提交,其源代碼與舊的提交6f374ed9
完全相同。 (換句話說,你想避免重寫歷史,因爲明顯的master
和task-e
已經被推送到GitHub。)這在git中需要幾個步驟,這在this question中描述。總而言之,首先確保您沒有未提交的更改(即git status
是乾淨的)。然後,您需要做的:
# 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 [email protected]{1}
# Commit the result:
git commit -m "Reverting state back to 6f374ed9"
然後,更新task-e
,以及,你可以這樣做:
git checkout task-e
git merge master
您可以使用git reset
,但它會重寫已經公開推送的歷史記錄,所以不建議。我會使用git revert
:它允許你恢復一個提交,即。它會創建一個與提交相反的提交。這樣,您可以取消提交併恢復到您想要的狀態,而無需重寫歷史記錄。