gpt4 book ai didi

Git - 压缩后恢复中间提交

转载 作者:太空狗 更新时间:2023-10-29 13:08:32 24 4
gpt4 key购买 nike

我已将多个提交压缩为一个提交。压缩之前的提交之一包括调试打印,后来的提交与它一起压缩删除了这些打印。有什么方法可以恢复它们吗?

最佳答案

是的。使用 git reflog 然后 git checkout 在压缩之前提交哈希。

这是事件序列的示例。

git init .
touch Foo1 Foo2 Foo3
git add Foo1
git commit -m 'Adding Foo1'
git add Foo2
git commit -m 'Adding Foo2'
git add Foo3
git commit -m 'Adding Foo3'
git log # Observe all three commits
git rebase -i --root # Squash commits

git reflog
87a5159 HEAD@{0}: rebase -i (finish): returning to refs/heads/master
87a5159 HEAD@{1}: rebase -i (squash): Adding Foo1
a0eecf4 HEAD@{2}: rebase -i (squash): # This is a combination of 2 commits.
4142aa5 HEAD@{3}: rebase -i (pick): Adding Foo1
85ad082 HEAD@{4}: rebase -i (pick): Adding Foo1
cbc3a0c HEAD@{5}: rebase -i (start): checkout cbc3a0c02d1899dcfcc614afc07b3a5a502af56f
71697f7 HEAD@{6}: commit: Adding Foo3

git checkout HEAD@{6} # get back original commits, with head detached.

关于Git - 压缩后恢复中间提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36058453/

24 4 0