2017-07-02 148 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