假设我提交了 A-B-C-D-E-F。请注意,所有提交都已推送到上游。
我想恢复到提交 D,但也想在分支中保留提交 E 和 F。
所以我想做的是创建一个提交 G,它的内容与 D 相同。最后我的分支看起来像 A-B-C-D-E-F-G,D=G。
我该怎么做?
答案 0 :(得分:2)
您只需要获取 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