签出旧的提交并使其成为新的提交 [英] Checkout old commit and make it a new commit

查看:77
本文介绍了签出旧的提交并使其成为新的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git上,说我搞砸了我的提交,并且我想让第3版作为新版本提交。如果我执行 git checkout xxxx ,它会创建一个新的分支并且好像我只能合并它?我可以做这个新的主版本吗?



我想:

  ABCDE 

成为

 ABCDEF 

其中F的内容与C

如果我使用 git回复xxxx ,它似乎肯定会有冲突,我需要手动解决它。



我真正想要的只是在某个时刻使旧提交成为新提交,而不管我的工作目录或最新提交中的内容。



我会如何去做这件事?

解决方案

  git rm -r。 
git checkout HEAD〜3。
git commit

提交后,新的头文件将与修订 HEAD〜3 中的相同。


On Git, say I mess up my commits, and I want to make the version 3 commits ago as the new version. If I do git checkout xxxx, it creates a new branch and it seems like I can only merge it? Could I make this the new "master version"?

I want:

A-B-C-D-E

to become

A-B-C-D-E-F

where F has exactly the same content as C

If I use git revert xxxx instead, it seems like it definitely will have conflicts and I need to manually resolve it.

What I really want is just make the old commit at some point the new commit, regardless of what's in my working directory or the latest commit.

How would I go about doing this?

解决方案

git rm -r .
git checkout HEAD~3 .
git commit

After the commit, files in the new HEAD will be the same as they were in the revision HEAD~3.

这篇关于签出旧的提交并使其成为新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆