我試圖用git replace
改寫歷史並更換樹 的犯了一個不同的樹對象提交。我想使這個 永久。如何使用git替換替換的樹提交
documentation for git replace
似乎表明這是 可能。我改編了以下配方來取代How to prepend the past to a git repository?的提交。
# setup a second branch with a different tree
# existing repo which already contains a few commits
git checkout master -b master2
echo "test file" > testfile.txt # a different tree
git add testfile.txt
git commit -m "test"
# save the SHA1 of the original tree for later reference
ORIG=$(git rev-parse master^{tree})
# replace the tree of master with the one from master2
git replace master^{tree} master2^{tree}
# verify the contents of the replaced tree
git ls-tree master
這個作品,大師的樹已經被從master2的一個替代,包括 額外的文件:
100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad readme.txt
100644 blob 16b14f5da9e2fcd6f3f38cc9e584cef2f3c90ebe testfile.txt
然而,試圖讓這永久的,失敗:
git filter-branch --tag-name-filter cat -- --all
從git得到以下回復:
Rewrite e7619af3e5d424a144845c164b284875c4c20c7a (2/2)
WARNING: Ref 'refs/heads/master' is unchanged
WARNING: Ref 'refs/heads/master2' is unchanged
error: Object bc705106db90164b2e688b4b190d4358f8b09a56 is a tree, not a commit
error: Object bc705106db90164b2e688b4b190d4358f8b09a56 is a tree, not a commit
fatal: ambiguous argument 'refs/replace/e7a75e980c7adc0d5ab1c49ecff082b518bb6cf8^0':
unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
WARNING: Ref 'refs/replace/e7a75e980c7adc0d5ab1c49ecff082b518bb6cf8' is unchanged
後,我取下更換參考,高手指點原來的樹回來:
git replace -d ${ORIG}
git ls-tree master
3b18e512dba79e4c8300dd08aeb37f8e728b8dad readme.txt
爲什麼git filter-branch
抱怨更換和我怎麼做 更換樹的永久的嗎?
P.S.我知道我可以用filter-branch --tree-filter
或移植物做到這一點,但 (如何)可以用git replace
來做到這一點?
爲什麼你會用git替換它,當有其他方法時? – CodeFanatic
我認爲我可以用樹型過濾器來做到這點,但這會慢很多,而且會更加笨重。我可以通過移植來實現,但http://stackoverflow.com/questions/6800692/how-do-git-grafts-and-replace-differ-are-grafts-now-deprecated和其他鏈接建議移植現在應該完成與git替換。 Ultimataly,我不明白爲什麼git對我的咒語不滿意,我想明白爲什麼。 – fraco
我今天剛遇到同樣的問題。這個鏈接有一些相關的信息。 http://git.661346.n2.nabble.com/BUG-git-filter-branch-does-not-make-tree-replacements-permanent-td7582467.html – ChrisH