我在功能上工作(分支),在进度期间,我删除了一个文件不再使用,但是由于某种原因,我需要它。
所以我这样做了:
git checkout hashofcommit0 -- path/to/my/file
它有效,但我在文件上丢失了所有注释。我真的需要注释。
当然,我可以创建一个新的分支,应用我的最后一个分支(除了删除文件除外),并感到高兴。
(0) ->(1) ->(..) ->(n)
是否有解决方案可以返回提交(0),撤消删除,然后返回最后提交(n),没有冲突?
git rebase -i hashofcommit0
标记为 edit
您删除文件
当重新命中操作到达该提交时,它应该为您提供控制权和外壳
git add name_of_file
git commit --amend
git rebase --continue
让我知道
腕表的阐述
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
您将在有缺陷的提交的情况下提示您在壳中遇到外壳
例如,用命令恢复错过的文件:
git checkout HEAD^ -- nameOfMissedFile
然后重新添加它,然后修改订单之前继续进行rebase
git add nameOfMissedFile
git commit --amend (confirm or change the comment of the commit)
git rebase --continue