如何在git中重新设置几个独立分支中的提交范围?

如何在git中重新设置几个独立分支中的提交范围?,git,git-branch,git-merge,Git,Git Branch,Git Merge,我需要重新安排一个“线性结构” “叉形结构” 示例:让我们从一个分支(命名为temp)开始,该分支派生自主分支,然后让我们放置几个提交-C1C10。 与此相反,我希望有两个基于master的分支(每个特性一个)。我可以通过引用C1之前的提交来创建这两个分支。然后,如何重新排列(合并?)所有提交,以便在分支-1中从C1到C5(源于master)进行提交,并在分支-2中从C6到C10进行分支?在分支2的日志中,我希望有C0,C6..C10(其中C0是主分支中的最后一次提交) 可能可以通过重命名tem

我需要重新安排一个“线性结构”

“叉形结构”

示例:让我们从一个分支(命名为temp)开始,该分支派生自主分支,然后让我们放置几个提交-C1C10。 与此相反,我希望有两个基于master的分支(每个特性一个)。我可以通过引用C1之前的提交来创建这两个分支。然后,如何重新排列(合并?)所有提交,以便在分支-1中从C1C5(源于master)进行提交,并在分支-2中从C6C10进行分支?在分支2的日志中,我希望有C0C6..C10(其中C0主分支中的最后一次提交)

可能可以通过重命名temp并执行以下操作来检索分支-1

git reset --hard  HEAD~5 #or 4 (?)
但是对于分支-2如何删除C1..C5并保留其余部分

编辑:以下是可用于重现案例的测试脚本:

#!/bin/bash

## file names
file1='file1'
file2='file2'

## clean-up for fresh start
if [ -d .git ] 
then
    rm -rf .git
fi
## create files
echo start1 > $file1
echo start2 > $file2

## start the repository creation 
git init
git add $file1 $file2
git commit -am 'C0'

## linear branch
git checkout -b temp

## implement features 1 & 2 in files 1 & 2
for i in {1..10}
do
    if [ $i -le 5 ]
    then
    file=$file1
    else
    file=$file2
    fi
    msg='line '$i
    echo $msg >> $file
    git commit -m "C$i" $file
done
git reset --hard  HEAD~5 #or 4 (?)
#!/bin/bash

## file names
file1='file1'
file2='file2'

## clean-up for fresh start
if [ -d .git ] 
then
    rm -rf .git
fi
## create files
echo start1 > $file1
echo start2 > $file2

## start the repository creation 
git init
git add $file1 $file2
git commit -am 'C0'

## linear branch
git checkout -b temp

## implement features 1 & 2 in files 1 & 2
for i in {1..10}
do
    if [ $i -le 5 ]
    then
    file=$file1
    else
    file=$file2
    fi
    msg='line '$i
    echo $msg >> $file
    git commit -m "C$i" $file
done
git branch branch-1 C5
git branch -m temp branch-2
git rebase --onto C0 branch-1 branch-2