無関係な履歴は、を使用して結合できますgit filter-branch
。これがマンページからの抜粋です:
To set a commit (which typically is at the tip of another history) to be the
parent of the current initial commit, in order to paste the other history behind
the current history:
git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' HEAD
(if the parent string is empty - which happens when we are dealing with the
initial commit - add graftcommit as a parent). Note that this assumes history
with a single root (that is, no merge without common ancestors happened). If
this is not the case, use:
git filter-branch --parent-filter \
'test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>" || cat' HEAD
or even simpler:
git replace --graft $commit-id $graft-id
git filter-branch $graft-id..HEAD
あなたの場合、$commit-id
は最初の青いコミットで$graft-id
あり、最後の赤いコミットです。
完全な手順の例を次に示します。
リポジトリといくつかの赤いコミットを作成しましょう:
$ git init
$ echo a >a
$ git add a
$ git commit -m c1
[master (root-commit) 6a6b98f] c1
1 file changed, 1 insertion(+)
create mode 100644 a
$ echo b >>a
$ git add a
$ git commit -m c2
[master d91d385] c2
1 file changed, 1 insertion(+)
次に、無関係のブランチo1
を作成し、いくつかの青いコミットを追加します。
$ git checkout --orphan=o1
Switched to a new branch 'o1'
$ echo c >>a
$ git add a
$ git commit -m c3
[o1 (root-commit) ed2b106] c3
1 file changed, 3 insertions(+)
create mode 100644 a
$ echo d >>a
$ git add a
$ git commit -m c4
[o1 5b655a6] c4
1 file changed, 1 insertion(+)
必要なものが得られたことを確認します。
$ git log --format=short --graph --all
* commit 5b655a615f8a729c123d89180ca1928451b465b2 (HEAD -> o1)
|
| c4
|
* commit ed2b106d7bd0ffef317a723f2921808bc8ad9f45
c3
* commit d91d385c7811ba07f4092133c435b55323562686 (master)
|
| c2
|
* commit 6a6b98fca7150839f607d9d55c6b9f10861375f8
c1
(c2、最後の赤)を新しい親として、ed2b106
(c3、最初の青)のグラフトコミットを作成しますd91d385
。
$ git replace --graft ed2b106d7bd0ffef317a723f2921808bc8ad9f45 d91d385c7811ba07f4092133c435b55323562686
$ git log --format=short --graph --all
* commit 5b655a615f8a729c123d89180ca1928451b465b2 (HEAD -> o1)
|
| c4
|
* commit ed2b106d7bd0ffef317a723f2921808bc8ad9f45 (replaced)
|
| c3
|
| * commit 4656e5bca003770b1a35aff10e3ffb51f7fb1ad9
|/
| c3
|
* commit d91d385c7811ba07f4092133c435b55323562686 (master)
|
| c2
|
* commit 6a6b98fca7150839f607d9d55c6b9f10861375f8
c1
4656e5b
固定された親との置き換えとして(修正されたc3)を取得しましたが、その置き換えはローカルのみであるため、すべての青いコミットを書き直す必要があります。
$ git filter-branch d91d385c7811ba07f4092133c435b55323562686..HEAD
Rewrite 5b655a615f8a729c123d89180ca1928451b465b2 (2/2) (0 seconds passed, remaining 0 predicted)
Ref 'refs/heads/o1' was rewritten
$ git log --format=short --graph
* commit 2cf6b0d3a0ee2deff99bbe327d065f90c82c1c2b (HEAD -> o1)
|
| c4
|
* commit 4656e5bca003770b1a35aff10e3ffb51f7fb1ad9
|
| c3
|
* commit d91d385c7811ba07f4092133c435b55323562686 (master)
|
| c2
|
* commit 6a6b98fca7150839f607d9d55c6b9f10861375f8
c1
4656e5b
(固定されたC3)既に(同様に良好であったed2b106
だけ異なる親を持つ、元C3)が、5b655a6
その親となるように(C4)が書き換えられた4656e5b
(固定されたC3)の代わりにed2b106
(元のC3)。これed2b106
で、履歴で使用されなくなった交換品を安全にドロップできます。
$ git replace -d ed2b106d7bd0ffef317a723f2921808bc8ad9f45
Deleted replace ref 'ed2b106d7bd0ffef317a723f2921808bc8ad9f45'
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加