file1; git init; git add .; git commit -m "initial - file 1" -6ren">
gpt4 book ai didi

git - 如何在对同一提交进行 rebase 后恢复 merge 提交?

转载 作者:太空狗 更新时间:2023-10-29 14:24:03 25 4
gpt4 key购买 nike

假设这样:

mkdir test; cd test
echo "1" > file1; git init; git add .; git commit -m "initial - file 1" # 1st commit on master
echo "2" > file2; git add .; git commit -m "file 2" # 2nd commit on master
git checkout -b newbranch # creates newbranch
echo "1" >> file1; git add .; git commit -m "changed 1" # 1st commit on newbranch
git checkout master # goes to master
echo "2" >> file2; git add .; git commit -m "changed 2" # 3rd commit on master
git merge newbranch -m "merge commit" # merge newbranch on master
echo "3" > file3; git add .; git commit --amend -m "merge commit" # amend merge commit and adds file3
git rebase HEAD~2 # don't change anything, just leave
ls # there isn't file3 anymore!

有没有办法恢复 merge 提交,这样修改后的更改就不会丢失?

最佳答案

您所做的更改仍在您的reflog中。

在意外 rebase 之后(我假设这是意外,因为你在谈论“丢失”提交),运行 git reflog

找到最顶层集合中最后一个“rebase:”行正下方的条目。它左边的提交散列是在你开始 rebase 之前修改后的 merge 提交。

关于git - 如何在对同一提交进行 rebase 后恢复 merge 提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15714029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com