3 回答

TA貢獻(xiàn)1818條經(jīng)驗 獲得超7個贊
正如提到的ecdpalma 下面,GIT中1.7.12+(2012年8月)具有增強(qiáng)的選項--root
為git rebase
:
“ git rebase [-i] --root $tip
”現(xiàn)在可用于重寫所有導(dǎo)致“ $tip
”到根提交的歷史記錄。
這個新行為最初在這里討論:
我個人認(rèn)為“
git rebase -i --root
”應(yīng)該只是工作而不需要“--onto
”讓你“編輯”甚至是歷史上的第一個。
可以理解的是,沒有人會感到困擾,因為人們在歷史的最初階段重寫的次數(shù)要少得多。
隨后是補(bǔ)丁。
(原答案,2010年2月)
創(chuàng)建新的臨時分支
將其回滾到您要使用的更改提交
git reset --hard
更改提交(它將是當(dāng)前HEAD的頂部,您可以修改任何文件的內(nèi)容)
Rebase分支在更改提交之上,使用:
git rebase --onto <tmp branch> <commit after changed> <branch>`
訣竅是確保您要刪除的信息不會被文件中其他位置的后續(xù)提交重新引入。如果您懷疑,那么您必須使用filter-branch --tree-filter
以確保該文件的內(nèi)容在任何提交中都不包含敏感信息。
在這兩種情況下,您最終都會重寫每次提交的SHA1,因此如果您已經(jīng)發(fā)布了要修改其內(nèi)容的分支,請務(wù)必小心。你可能不應(yīng)該這樣做,除非你的項目尚未公開,而其他人沒有基于你即將重寫的提交工作。

TA貢獻(xiàn)1862條經(jīng)驗 獲得超6個贊
git rebase -i允許您方便地編輯除根提交之外的任何先前提交。以下命令顯示如何手動執(zhí)行此操作。
# tag the old root, "git rev-list ..." will return the hash of first commit
git tag root `git rev-list HEAD | tail -1`
# switch to a new branch pointing at the first commit
git checkout -b new-root root
# make any edits and then commit them with:
git commit --amend
# check out the previous branch (i.e. master)
git checkout @{-1}
# replace old root with amended version
git rebase --onto new-root root
# you might encounter merge conflicts, fix any conflicts and continue with:
# git rebase --continue
# delete the branch "new-root"
git branch -d new-root
# delete the tag "root"
git tag -d root
- 3 回答
- 0 關(guān)注
- 852 瀏覽
添加回答
舉報