簡體   English   中英

git - 設置一個沒有rebase的commit的父級

[英]git - setting a commit's parent without rebase

我用git-svn創建了一個SVN存儲庫的git鏡像。 SVN內部的結構有點不合標准,因此git創建了一個與master分支沒有共同提交的分支。

      A---B---C topic

D---E---F---G master

我知道提交A是基於提交E而且我非常肯定我已經解決了導致git無法識別該事實的問題(使用filter-branch )。 我想要做的是將topic重新附加到master分支,將E設置為A的父A

      A---B---C topic
     /
D---E---F---G master

git-rebase似乎對我不起作用,因為提交A的diff列出了master中已經存在的大量文件的創建,導致了大量的沖突。
根據我對git的理解,將E設置為A的父A應該足以解決所有問題。
這可能嗎? 如果是,我該怎么辦?

看看移植物(移植文件可以在.git/info/grafts )。 格式非常簡單:

<commit sha1> <parent1 sha1> <parent2 sha1> … <parentN sha1>

這使得git相信提交的父母與實際擁有的不同。 使用filter-branch使移植物永久化(因此可以移除移植物文件):

git filter-branch --tag-name-filter cat -- --all

請注意,這會重寫存儲庫的歷史記錄 ,因此不應在共享存儲庫中使用!


例如,如果您只想重寫正在移植到主分支上的提交的歷史記錄,請使用以下命令:

git filter-branch --tag-name-filter cat -- master..

基於你的圖表(雖然我關心你的意思“我非常肯定我已經修復了導致git不能識別這個事實的問題(使用filter-branch )。”),你應該能夠做類似以下的事情。

# checkout A
git checkout A

# Reset the branch pointer to E so that E is the parent of the next commit
# --soft ensures that the index stays the same
git reset --soft E

# Remake the commit with the E as the parent, re-using the old commit metadata
git commit -C HEAD@{1}

# Rebase the topic branch onto the modified A commit (current HEAD)
git rebase --onto HEAD A topic

你需要的只是這個:

git rebase --root --onto master^^ topic^^ topic

root選項允許你包括A.

更新:

如果要保留要變基的零件的分支和合並,請添加--preserve-merges選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM