与所有子分支git rebase分支 [英] git rebase branch with all subbranches

查看:157
本文介绍了与所有子分支git rebase分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我经常使用分支作为快速/可变的标记来标记某些提交。

有可能使用git中的所有子分支来重新分支分支吗?

  * master 
*
* featureA-finished
*
* origin / master

现在我想要 rebase -i master origin / master ,改变/ reword提交 featureA-finished ^ git rebase -i --onto origin / master origin / master master 之后,我基本上想要历史记录:

  * master 
*
* featureA-finished
*(changed / reworded)
* origin / master

但是我得到的是:


$ b $

  * master 
*
*(与featureA完成的变更集相同)
*(更改/重写)
| * featureA-finished
。。*(我想编辑的原始提交)
* origin / master

是否有解决方法,或者我坚持重新创建新的重新提交的提交上的分支?

解决方案

根据git的对象模型,如果您只更改提交的元数据(即提交消息),但不包含其中包含的基础数据(树(s)),那么它的Tree哈希将保持不变。除了编辑提交消息,你也在执行一个rebase,它会改变你历史中每个提交的树散列,因为从 origin / master 引出的任何变化都会影响你重新编译的文件,书面历史:这意味着你的提交指向的一些文件(斑点)已经改变。



所以没有防弹的方法去做你想做的事情。 / p>

在编辑提交时使用 rebase -i 通常不会改变提交的时间戳记和作者,因此您可以使用它在rebase操作前后唯一标识您的提交。


您必须编写一个脚本,在执行rebase之前记录所有分支起点与这些timestamp:author标识符,然后查找重写的提交相同的时间戳:作者ID并重新绑定分支。



可悲的是,我现在没有时间自己写这个脚本,所以我只能祝你好运!



编辑:您可以使用以下方式获取作者的电子邮件地址和时间戳:

  $ git log --graph --all --pretty = format:%h%ae:%ci
* 53ca31a robert.meerman @ gmail.com:2010-06-16 13:50:12 +0100
* 03dda75 robert.meerman@gmail.com:2010-06-16 13:50:11 +0100
| * a8bb03a robert.meerman@gmail.com:2010-06-16 13:49:46 +0100
| * b93e59d robert.meerman@gmail.com:2010-06-16 13:49:44 +0100
| /
* d4214a2 robert.meerman@gmail.com:2010-06-16 13:49 :41 +0100

您可以根据它们的提交散列获取每个分支的列表:

  $ git branch --contains 03dda75 
* testbranch

注意每个提交的多个分支,共同的祖先 d4214a2 属于两个分支!


is it possible to rebase a branch with all it's subbranches in git?

i often use branches as quick/mutable tags to mark certain commits.

* master
*
* featureA-finished
*
* origin/master

now i want to rebase -i master onto origin/master, to change/reword the commit featureA-finished^

after git rebase -i --onto origin/master origin/master master, i basically want the history to be:

* master
*
* featureA-finished
* (changed/reworded)
* origin/master

but what i get is:

* master
*
* (same changeset as featureA-finished)
* (changed/reworded)
| * featureA-finished
|.* (original commit i wanted to edit)
* origin/master

is there a way around it, or am i stuck with recreating the branches on the new rebased commits?

解决方案

According to git's Object Model if you only change the meta-data of a commit (i.e. commit message) but not the underlying data ("tree(s)") contained within it then it's Tree hash will remain unchanged.

Aside from editing a commit message, you are also performing a rebase, which will change the Tree hashes of each commit in your history, because any changes pulled from origin/master will affect the files in your re-written history: which means some of the files (blobs) that your commit points to have changed.

So there is no bullet-proof way to do what you want.

That said, editing a commit with rebase -i does not usually alter the commit's timestamp and author, so you could use this to uniquely identify your commits before and after a rebase operation.

You would have to write a script which records all the branch start-points against these "timestamp:author" identifier before doing a rebase, and then find the rewritten commits with the same "timestamp:author" ID and rebase the branch on it.

Sadly, I don't have time to try writing this script myself now, so I can only wish you the best of luck!

Edit: You can obtain the author email address and timestamp using:

$ git log --graph --all --pretty=format:"%h %ae:%ci"
* 53ca31a robert.meerman@gmail.com:2010-06-16 13:50:12 +0100
* 03dda75 robert.meerman@gmail.com:2010-06-16 13:50:11 +0100
| * a8bb03a robert.meerman@gmail.com:2010-06-16 13:49:46 +0100
| * b93e59d robert.meerman@gmail.com:2010-06-16 13:49:44 +0100
|/
* d4214a2 robert.meerman@gmail.com:2010-06-16 13:49:41 +0100

And you can obtain a list of branches for each of these based on their commit hash:

$ git branch --contains 03dda75
* testbranch

Watch out for multiple branches per commit, the common ancestor d4214a2 belongs to both branches!

这篇关于与所有子分支git rebase分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆