2013-04-13 21 views
34

でパッチを作成してそれから私は別のブランチでgit apply patch.diffをやってみましたが、私はパッチが適用されませんました。 gitで使用できるdiffファイルからパッチファイルを作成するにはどうすればよいですか?gitのは、私が</p> <pre><code>git diff 13.1_dev sale_edit > patch.diff </code></pre> <p>をやってみました差分

$ git apply --ignore-space-change --ignore-whitespace diff.diff 
diff.diff:9: trailing whitespace. 

diff.diff:10: trailing whitespace. 
    function set_change_sale_date() 
diff.diff:12: space before tab in indent. 
     $this->sale_lib->set_change_sale_date($this->input->post('change_sale_date')); 
diff.diff:14: trailing whitespace. 

diff.diff:15: trailing whitespace. 
    function set_change_sale_date_enable() 
warning: application/controllers/sales.php has type 100755, expected 100644 
error: patch failed: application/controllers/sales.php:520 
error: application/controllers/sales.php: patch does not apply 
warning: application/language/english/sales_lang.php has type 100755, expected 100644 
error: patch failed: application/language/english/sales_lang.php:134 
error: application/language/english/sales_lang.php: patch does not apply 
warning: application/libraries/Sale_lib.php has type 100755, expected 100644 
error: patch failed: application/models/sale.php:170 
error: application/models/sale.php: patch does not apply 
warning: application/views/sales/register.php has type 100755, expected 100644 
error: patch failed: application/views/sales/register.php:361 
error: application/views/sales/register.php: patch does not apply 

を、私は、Mac

+1

Gitは間違ったツールです。 Gitは空白と改行を適切に処理しないので、パッチを適用しようとして何時間も費やすことができます。私は以前、3行のパッチを適用しようとしましたが、それは電子メールで私に送られたものです([Gitを使用しないでGitのファイルにパッチを適用してください](http://stackoverflow.com/q/35353267)) 。 'patch'プログラムを使用してください。空白と行末を処理します。 – jww

答えて

21

上でこれをしようとしているお試しください:受信

エラー

git apply --ignore-space-change --ignore-whitespace patch.diff 

"git: patch does not apply" で述べたように、これはが原因で発生することができ

  • 行末差分ローカルファイルシステムとリモートリポジトリの間でエラーが発生しました。
    ユーザーcore.eol.gitattributes内のファイルは良いアプローチである( "git force file encoding on commit" を参照)
  • 実行ビット( 'x')。
    git config core.filemode falseに設定し、その後にgit reset --hard HEADを設定することができます(コミットされていない変更がないか、失われていないことを確認してください)。
+0

executuionビットの詳細を教えてください。 – stdcall

+0

@Mellowcandle詳細はhttp://stackoverflow.com/a/4770223/6309 – VonC

+0

です。まだ適用されません。更新された質問 –

1

ここでは、あなたが持っているブランチで試してみる必要があります。

git diff 13.1_dev sale_edit > patch.diff yourBranch() 
10

あなたは3ウェイマージ、パッチを適用することができます。

git diff 13.1_dev sale_edit > patch.diff 
git apply -3 patch.diff 

手動で解決できるように、それは紛争を持参してください。 それとも、のgit-適用直接にパッチをパイプ、ワンライナーで行くことができる:

git diff 13.1_dev sale_edit | git apply -3 

パッチを逆にするには:

git diff 13.1_dev sale_edit | git apply -3 -R 

(注意:これは上記のコマンドと同じであり、使用「gitのdiffを」を使用して作成したパッチを適用するには「Gitは適用」がオンのとき、パッチファイルを作成するための2段階のプロセスなし)Gitのバージョン1.9.1で

git help apply 

-3, --3way   
When the patch does not apply cleanly, fall back on 3-way merge if 
the patch records the identity of blobs it is supposed to apply to, 
and we have those blobs available locally, possibly leaving 
the conflict markers in the files in the working tree for the user 
to resolve... 
1

、私は同様の苦情を見ています。

パッチファイル内のスペースが混在している1.9.1 gitが表示されているようです。 VonCの答え@

warning: squelched 1 whitespace error warning: 6 lines add whitespace errors.

助けにはならないと私はまだ同じ警告を取得しています。

最も簡単な解決策は、 'パッチ'コマンドを使用して、 'git diff'出力でキャプチャされたすべての変更を対象のgitディレクトリに正常に適用することです。

$ patch --version GNU patch 2.7.1

+0

コマンドパッチの面白い使い方。 +1 – VonC

関連する問題

 関連する問題