git 历史搞砸了
git history screwed up
我试图做变基以将提交合并为一个提交,但我最终写了更多的提交,现在一切都搞砸了。
这是树:
在 运行 git status
上,我得到
On branch master
Your branch is up to date with 'origin/master'.
Last commands done (5 commands done):
pick 49147e5 squash
pick 2c48387 Commit
(see more in file .git/rebase-merge/done)
Next commands to do (13 remaining commands):
pick fddd4c7 commit
pick 5f01f80 commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'master' on '1550461'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working tree clean
在 运行 git log --oneline
,我得到:
Merge branch 'master' of .....
49147e5 squash
0310431 commit 4 which was PR
d4be53f commit 6
ea24a2d commit 5
1550461 commit 3
fc8115a commit 2
212138a commit 1
72d8fff Merge pull request #64 from branch 1
c5ad199 commit 14
2a6ceaf commit 13
6660dbf commit 12
b6c863e commit 11
88788e6 commit 10
5bbe8a7 commit 9
9731810 commit 8
1e4ac6b commit 7
ce3817c Merge branch 'master' of .... into branch 1
ec4c3e9 commit 6
5b8900b commit 5
d10eec9 commit 4 which was PR
5f01f80 commit 3
fddd4c7 commit 2
02ebbc8 Merge branch 'master' of ....into branch 1
3995cf2 pr changes v2
2c48387 commit 1
我是如何搞砸的:
从 72d8fff
,我做了 git rebase -i HEAD~7 or 8
,git pull
,然后 git push
。我想 squash
d10eec9
之后的所有提交变成一个提交,但我想我最终写在了 HEAD 之上。
我想做 git reset --hard 72d8fff
然后 git push origin HEAD --force
这至少会让我回到我开始的地方。
请保存。
bring me back to where I started.
在本地,您可以查看 git reflog
,其中将列出本地存储库中已更新的分支和其他参考的提示。
你会在那里找到 HEAD 在你的变基之前引用的内容。
如果你 reset --hard
提交,你将回到变基之前。
您还可以将该提交与(如果您没有进行任何其他变基)进行比较 .
想法仍然是:首先在本地恢复您的历史记录,然后再次压缩您的最后一次提交(这次,without rebase, but using git reset --soft
),并在您的本地存储库状态令人满意后强制推送。
我试图做变基以将提交合并为一个提交,但我最终写了更多的提交,现在一切都搞砸了。
这是树:
在 运行 git status
上,我得到
On branch master
Your branch is up to date with 'origin/master'.
Last commands done (5 commands done):
pick 49147e5 squash
pick 2c48387 Commit
(see more in file .git/rebase-merge/done)
Next commands to do (13 remaining commands):
pick fddd4c7 commit
pick 5f01f80 commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'master' on '1550461'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working tree clean
在 运行 git log --oneline
,我得到:
Merge branch 'master' of .....
49147e5 squash
0310431 commit 4 which was PR
d4be53f commit 6
ea24a2d commit 5
1550461 commit 3
fc8115a commit 2
212138a commit 1
72d8fff Merge pull request #64 from branch 1
c5ad199 commit 14
2a6ceaf commit 13
6660dbf commit 12
b6c863e commit 11
88788e6 commit 10
5bbe8a7 commit 9
9731810 commit 8
1e4ac6b commit 7
ce3817c Merge branch 'master' of .... into branch 1
ec4c3e9 commit 6
5b8900b commit 5
d10eec9 commit 4 which was PR
5f01f80 commit 3
fddd4c7 commit 2
02ebbc8 Merge branch 'master' of ....into branch 1
3995cf2 pr changes v2
2c48387 commit 1
我是如何搞砸的:
从 72d8fff
,我做了 git rebase -i HEAD~7 or 8
,git pull
,然后 git push
。我想 squash
d10eec9
之后的所有提交变成一个提交,但我想我最终写在了 HEAD 之上。
我想做 git reset --hard 72d8fff
然后 git push origin HEAD --force
这至少会让我回到我开始的地方。
请保存。
bring me back to where I started.
在本地,您可以查看 git reflog
,其中将列出本地存储库中已更新的分支和其他参考的提示。
你会在那里找到 HEAD 在你的变基之前引用的内容。
如果你 reset --hard
提交,你将回到变基之前。
您还可以将该提交与(如果您没有进行任何其他变基)进行比较
想法仍然是:首先在本地恢复您的历史记录,然后再次压缩您的最后一次提交(这次,without rebase, but using git reset --soft
),并在您的本地存储库状态令人满意后强制推送。