[英]Git how to revert to a certain commit, but keep all the commits I made
假設我有提交 ABCDEF。 請注意,所有提交都已推送到上游。
我想恢復提交 D,但也想將提交 E 和 F 保留在分支中。
所以我想做的是創建一個提交G,它的內容與D相同。最后我的分支看起來像ABCDEFG,D=G。
我該怎么做呢?
您只需獲取D
的確切內容,並使用該內容創建提交:
# choose a. or b. :
# a. 'git restore' was added for this purpose in version 2.25,
# and has options which are more explanatory (readable at least) :
git restore --source D --staged --worktree -- .
# b. for older gits, or for people enjoying more obscure commands, there is 'git read-tree' :
git read-tree D
# after that :
# confirm that the content you expect is staged, and commit :
git status
git commit
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.