Git - 在 squash 之后恢复中间提交



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

是的。使用 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.
我知道

这是一个旧帖子,但也许其他人会发现这是相关的.
如果您尝试获取远程中的提交 ID 并且您在本地没有它......含义:其他人将一些提交推送到功能分支,然后针对开发分支打开一个 PR,并制定了壁球策略。你可以看到提交 id,但你的本地 git 不熟悉这个 ref.
您需要做的就是:
git fetch <commit_id>及其所有树都将可用.
我们使用 bitbucket 作为我们的 git 服务器,卷曲到数据的最新提交摘要中返回的 PR。 从那时起,很容易检索所有相关数据

最新更新