如何在Git中重新加入父项 [英] how to re-parent in Git

查看:121
本文介绍了如何在Git中重新加入父项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每种情况下,什么非交互式git命令实现了从before到after的变化?

1a。重新注册我



之前:

  A --- B --- C --- D 

After:

  C'--- D'
/
A --- B

1b。重新注册II



之前:

  C --- D 
/
A --- B

后:

  C 
/
A --- B --- D'

<1c。重新注册III



之前:

  C 
/
A --- B --- D

之后:

  C --- B'--- D'
/
A
code>


解决方案

这些都看起来像 git rebase --onto



1a。重新注册我之前

之前: --- C --- D

后:

  C'--- D'
/
A --- B



    $ b <$>设置分支来标记特定的提交,然后重新绑定到。

    c $ c> git checkout -b ex1a -b B
  1. git checkout -b ex1a -d D

  2. git checkout -b ex1a -a A

  3. git rebase - ex1a -a ex1a -b ex1a-d



1b。重新注册II



之前:

  C --- D 
/
A --- B

之后:

  C 
/
A --- B --- D'

创建类似以上的分支: git rebase --onto ex1b -b ex1b -c ex1b-d



1c。重新注册III



之前:

  C 
/
A --- B --- D

之后:

  C --- B'--- D'
/
A

再次使用分支,但现在只需 git rebase ex1c -c ex1c-d


What non-interactive git command(s) achieve the change from Before to After in each case?

1a. re-parenting I

Before:

A---B---C---D

After:

  C'---D'
 /
A---B

1b. re-parenting II

Before:

  C---D
 /
A---B

After:

  C
 /
A---B---D'

1c. re-parenting III

Before:

  C
 /
A---B---D

After:

  C---B'---D'
 /
A

解决方案

These all look like applications of git rebase --onto.

1a. re-parenting I

Before:

A---B---C---D

After:

  C'---D'
 /
A---B

Set up branches to label the particular commits and then rebase onto.

  1. git checkout -b ex1a-b B
  2. git checkout -b ex1a-d D
  3. git checkout -b ex1a-a A
  4. git rebase --onto ex1a-a ex1a-b ex1a-d

1b. re-parenting II

Before:

  C---D
 /
A---B

After:

  C
 /
A---B---D'

Creating branches similar to above: git rebase --onto ex1b-b ex1b-c ex1b-d.

1c. re-parenting III

Before:

  C
 /
A---B---D

After:

  C---B'---D'
 /
A

Again with the branches, but now just git rebase ex1c-c ex1c-d.

这篇关于如何在Git中重新加入父项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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