我正在使用某个功能(分支),在此过程中,我删除了不再使用的文件,但是由于某种原因,我需要将其退回。
所以我这样做了:
git checkout hashofcommit0 -- path/to/my/file
它可以工作,但是我丢失了文件上的所有注释。我真的需要注解
当然,我可以创建一个新分支,应用最后一个分支(除去的文件除外)进行的所有比较,然后感到高兴。
(0)->(1)->(..)->(n)
有没有解决方案可以返回到commit(0),撤消删除,然后返回到最后一个commit(n)且没有冲突?
详细阐述卡尔波的答案
git rebase -i hashofcommit0^ (note the ^ that indicate the father of your first commit)
系统会显示从旧到新的提交列表
pick hashofcommit0 comment of commit0
pick hashofcommit1 comment of commit1
pick hashofcommit2 comment of commit2
pick hashofcommit3 comment of commit3
pick hashofcommit4 comment of commit4
pick hashofcommit5 comment of commit5
...
仅更改pick
为edit
在错误提交的情况下,将提示您使用shell
例如,使用以下命令恢复丢失的文件:
git checkout HEAD^ -- nameOfMissedFile
然后重新添加它并修改提交,然后再继续进行变基
git add nameOfMissedFile
git commit --amend (confirm or change the comment of the commit)
git rebase --continue
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句