[英]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.