2017-07-02 171 views
0

我正在嘗試在git倉庫中重寫我的歷史,並且迄今取得了輕微的成功。 我嘗試使用rebasing來擺脫每個提交中的巨大文件,我一定做了錯誤的事情,因爲我結束了這個奇怪的形狀歷史。git改寫歷史(rebase舊分支?)

* 0758bb3 - (HEAD -> master, origin/master, origin/HEAD) 
|\ 
| * 1ff4a51 
| * f33555f 
(... a bunch of commits in the right-hand-size branch only) 
| * af4b7bf 
| * a9bf8d0 
| * f22fae8 
* | 68bd9eb 
* | 2e29133 
|/ 
* fbef4bf 

我想將其改造成:

* 0758bb3 - (HEAD -> master, origin/master, origin/HEAD) 
* 1ff4a51 
* f33555f 
(...) 
* af4b7bf 
* a9bf8d0 
* f22fae8 
* 68bd9eb 
* 2e29133 
* fbef4bf 

我想做到這一點應該看起來有點像

git checkout f22fae8 
git rebase 68bd9eb 
??? 
git push --force origin master 

但考慮到我怎麼一點都懂的方式「變基「現在,我無法掌握現有的信息來做到這一點。 我很抱歉,如果問題已經在某個地方回答了,我沒有找到它(可能是因爲我沒有看到應該用什麼詞來描述這種情況:/)。 非常感謝任何人可以幫助我:)

+0

是否可以重寫公共分支(如提交散列更改)?如果是的話,然後rebase,如果不是,你可以做分支合併。 – chenrui

回答

0

我不知道你在做什麼以上。如果你合併了分支並且看起來像上面那樣,那麼你已經擁有了你正在尋找的東西。但是如果你想讓它看起來不同,使用rebase,那麼你會有完全不同的提交。如果您正在重新綁定,那麼您基本上會創建與之前存在的提交相同的新提交。那麼然後提交歷史將看起來不一樣。這裏是一個例子,它可以將上述結構轉換爲您正在查找的內容 - 但帶有新的提交。

// First set up another branch where you can safely rebase 

git checkout fbef4bf 
git checkout -b rebase-point 

// now switch to the place you want to rebase from: 

git checkout master 
git rebase rebase-point  

// if satisfied, set the master branch to point to the 0758bb3 commit equivalent (remember we are rebasing so it won't be the same commit). 

git reset --hard rebase-point