假设:
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!
有没有办法恢复合并提交,以便修改它的更改不会丢失?
答案 0 :(得分:0)
您所做的更改仍在 reflog 中。
意外重组后(我假设它是偶然的,因为你在谈论“丢失”提交),运行git reflog
。
找到最上面一组中最后一个“rebase:”行下方的条目。在您开始重新定位之前,它左边的提交哈希就是修改后的合并提交。