混帐:如何合并存在于先前丢失的文件提交到最新提交
问题描述:
原来提交包含5个文件:混帐:如何合并存在于先前丢失的文件提交到最新提交
a.txt
b.txt
c.txt
d.txt
e.txt
下一个提交补充道线的a.txt
底部,删除b.txt
和上载新文件f.txt
。即
a.txt - additions from second commit
c.txt
d.txt
e.txt
f.txt - new file from second commit
我想合并的提交,让我接受改变a.txt
,从第一次提交恢复b.txt
并添加f.txt
从最新的提交。回购现在应该是这样的:
a.txt - additions from second commit
b.txt - restored from first commit
c.txt
d.txt
e.txt
f.txt - new file from second commit
我试着用git rebase --root -i
这样做的,离开原来承诺的“选择”,改变了第二承诺“南瓜”
即
pick commit1
squash commit2
但rebase完成后,我只剩下commit2
我做错了什么,或者是我所问的不可能?
答
如果你想在一个特定的给定文件(S)提交的内容,只需运行:
git checkout <commit> -- file1 [file2 ...]
看起来你只需要做:
# get the version of b.txt from your previous commit :
git checkout <original commit> -- b.txt
# you will now see 'b.txt' as staged for commit :
git status
# create a new commit on top of the previous one :
git commit
我相信你不能选择一个提交_partially_,就像你想要做的第二次提交。但是,因为我不是专家,所以我会去检查是否有其他人有这样的魔力:) –