122

昨日マスターから作成されたgitブランチ(v4と呼ばれる)があります。マスターにはいくつかの変更があり、v4に入れたいと思っています。そのため、v4では、マスターからリベースを実行しようとしましたが、1つのファイルで問題が発生し続けます。バージョン番号を含む1行のテキストファイルです。このファイルはapp/views/common/version.txt、リベース前に次のテキストが含まれています。

v1.4-alpha-02

これが私がしていることです:

> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

version.txtは次のようになります。

<<<<<<< HEAD:app/views/common/version.txt
v1.4-alpha-02
=======
v1.4-alpha-01
>>>>>>> new version, new branch:app/views/common/version.txt

だから、私はそれを片付けます、そしてそれは今このように見えます:

v1.4-alpha-02

それから私は続けようとしました:最初に私はコミットを試みます:

> git commit -a -m "merged"
# Not currently on any branch.
nothing to commit (working directory clean)

運がない。だから、私はファイルを追加しようとしていました:

git add app/views/common/version.txt

応答なし。良いニュースはないでしょう。だから、私は続けようとします:

> git rebase --continue
Applying: new version, new branch
No changes - did you forget to use 'git add'?

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

この時点で、これをぐるぐる回った後、私は机から頭を叩いています。

何が起きてる?私は何が間違っているのですか?誰かが私をまっすぐに設定できますか?

編集-unutbuの場合

あなたが提案したようにファイルを変更しましたが、同じエラーが発生します:

> git rebase master
First, rewinding head to replay your work on top of it...
Applying: new version, new branch
error: patch failed: app/views/common/version.txt:1
error: app/views/common/version.txt: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging app/views/common/version.txt
CONFLICT (content): Merge conflict in app/views/common/version.txt
Failed to merge in the changes.
Patch failed at 0001 new version, new branch

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
4

6 に答える 6

105

リベースで同様の問題が発生しました。私の問題は、コミットの1つがファイルのみを変更したために発生し、解決時に、このコミットで導入された変更を破棄しました。対応するコミット()をスキップすることで問題を解決することができましたgit rebase --skip

この問題は、テストリポジトリで再現できます。まず、リポジトリを作成します。

$ mkdir failing-merge
$ cd failing-merge
$ git init
Initialized empty Git repository in $HOME/failing-merge/.git/

version.txt次に、マスターの元のコンテンツをコミットします。

$ echo v1.4-alpha-02 > version.txt
$ git add version.txt
$ git commit -m initial
[master (root-commit) 2eef0a5] initial
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 version.txt

v4ブランチを作成し、の内容を変更しますversion.txt

$ git checkout -b v4
Switched to a new branch 'v4'
$ echo v1.4-alpha-03 > version.txt
$ git add version.txt
$ git commit -m v4
[v4 1ef8c9b] v4
 1 files changed, 1 insertions(+), 1 deletions(-)

に戻ってmaster内容を変更しversion.txt、リベース中に競合が発生するようにします。

$ git checkout master
Switched to branch 'master'
$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git commit -m master
[master 7313eb3] master
 1 files changed, 1 insertions(+), 1 deletions(-)

ブランチに戻り、v4リベースしてみてください。version.txt計画どおりに競合して失敗します。

$ git checkout v4
Switched to branch 'v4'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: v4
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging version.txt
CONFLICT (content): Merge conflict in version.txt
Recorded preimage for 'version.txt'
Failed to merge in the changes.
Patch failed at 0001 v4

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
$ cat version.txt
<<<<<<< HEAD
v1.4-alpha-04
=======
v1.4-alpha-03
>>>>>>> v4

masterの内容を選択することで競合を解決しversion.txtます。ファイルを追加して、リベースを続行しようとします。

$ echo v1.4-alpha-04 > version.txt
$ git add version.txt
$ git rebase --continue 
Applying: v4
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

失敗します!gitリポジトリにどのような変更があると思われるか見てみましょう。

$ git status
# Not currently on any branch.
nothing to commit (working directory clean)

ああああ、変化はありません。以前のエラーメッセージを詳しく読んだ場合は、そのことをgit通知し、を使用することをお勧めしますgit rebase --skip。彼は、「ステージに残っているものがない場合は、他の何かがすでに同じ変更を導入している可能性があります。このパッチをスキップすることをお勧めします。」したがって、コミットをスキップするだけで、リベースは成功します。

$ git rebase --skip
HEAD is now at 7313eb3 master

注意:リベースしようとしgit rebase --skipたコミットは完全に削除されることに注意してください。私たちの場合、これは空のコミットであると不平を言っているgitので、これは問題ないはずです。gitリベースが完了した後で変更を失ったと思われる場合は、git reflogリベースの前にリポジトリのコミットIDを取得し、を使用git reset --hardしてデポをその状態に戻すことができます(これは別の破壊的な操作です)。

于 2011-01-31T14:06:02.477 に答える
23

ここから引用:http ://wholemeal.co.nz/node/9

は?!?いいえ、git addを使用することを忘れませんでした、私はそれをしました...のように... 2秒前!

パッチからの変更がないため、gitは何かが間違っていると疑っています。Gitはパッチが適用されていることを期待していますが、ファイルは変更されていません。

エラーメッセージはあまり直感的ではありませんが、答えは含まれています。このパッチをスキップするようにrebaseに指示する必要があります。また、ファイル内の競合マーカーを修正する必要はありません。最終的には、リベースしているブランチのファイルバージョンになります。

$ git rebase --skip
于 2011-01-31T10:35:11.000 に答える
6

app / views / common/version.txtをに変更します

v1.4-alpha-01

リベースのこの時点で、非マスターブランチの進行を示すためにマージの競合を解決していることを忘れないでください。

だから、からのリベースで

      A---B---C topic
     /
D---E---F---G master

              A*--B*--C* topic
             /
D---E---F---G master

解決しようとしている競合は、トピックブランチでA*を作成する方法にあります。

したがって、実行後git rebase --abort、コマンドは次のようになります。

git checkout topic
git rebase master
< make edits to resolve conflicts >
git add .
git rebase --continue
于 2010-10-27T12:19:26.630 に答える
6

そのエラーメッセージはあなたの結果ですgit commit -a -m "merged"。ファイルを修正してから、、を実行するgit add <file>git rebase --continue、正常に動作するはずです。git rebase --continueはコミットを実行しようとしていますが、コミットする保留中の変更がないことがわかりました(すでにコミットしているため)。

于 2012-05-22T15:18:24.750 に答える
4

あなたが見ている振る舞いは、この衝突だけで典型的なリベースから私が期待するものではありません。このリベースを行うために別のブランチを使用することを検討してください(特に、早送りしているコミットをリモートでプッシュしている場合)。また、git mergetool競合を解決し、を発行することを忘れないようにするのに役立ちますgit add

この最小限の例では、リベースは期待どおりに機能します。あなたが見ている行動を示す例を提供できますか?

#!/bin/bash

cd /tmp
mkdir rebasetest
cd rebasetest
git init
echo 'v1.0' > version.txt
git add version.txt
git commit -m 'initial commit'
git checkout -b v4
echo 'v1.4-alpha-01' > version.txt
git add version.txt
git commit -m 'created v4'
git checkout master
git merge v4
echo 'v1.4-alpha-01-rc1' > version.txt
git add version.txt
git commit -m 'upped version on master to v1.4-alpha-01-rc1'
git checkout v4
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git commit -m 'starting work on alpha-02'

git rebase master
echo 'v1.4-alpha-02' > version.txt
git add version.txt
git rebase --continue
于 2010-10-27T13:25:30.313 に答える
4

ここにいくつかのアイデアがあります:

于 2011-01-24T23:55:52.177 に答える