2012-11-02 11 views
13

में एक पैच लागू मैं एक उथले क्लोन, जिस पर मैं तीन प्रतिबद्ध बनाया है।
के दौरान त्रुटि Git

$ git log --oneline --graph --decorate --all
* d3456fd (HEAD, master) patch 3
* 9713822 patch 2
* 6f380a6 patch 1
* 8a1ce1e (origin/master, origin/HEAD) from full clone
* 7c13416 added from shallow
* 3b3ed39 removed email
* cfbed6c further modifications
* a71254b added for release 2.1
* 7347896 (grafted) changes for release 2

अब मैं यहाँ से एक पैच बनाने के लिए:: यहाँ लॉग है

$ git format-patch -k --stdout origin > ../format_since_origin.patch

मैं एक और क्लोन, जो एक पूर्ण क्लोन है में इस पैच लागू करना चाहते हैं।

$ git log --oneline --graph --decorate --all
* 8a1ce1e (HEAD, origin/master, master) from full clone
* 7c13416 added from shallow
* 3b3ed39 removed email
* cfbed6c further modifications
* a71254b added for release 2.1
* 7347896 changes for release 2
* b1a8797 changes to ttwo files
* 603710c changed test report
* 16b20b3 added test_report.txt
* f0871ea modified file1.xml
* dd94bfc added file1.xml
* 00758aa second commit
* 49f9968 first commit

मैं ऊपर उथले क्लोन से बनाए गए पैच लागू करने में असमर्थ हूँ:
यहाँ लॉग है। मुझे निम्नलिखित त्रुटि मिलती है।

$ git am -3 /c/temp/git/format_since_origin.patch
Applying: patch 1
Using index info to reconstruct a base tree...
error: patch failed: file1.c:6
error: file1.c: patch does not apply
Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Cannot fall back to three-way merge.
Patch failed at 0001 patch 1
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".

कोई विचार क्यों यह पैच विफल हो रहा है? या मेरी विधि पूरी तरह से गलत है?

अद्यतन:

यह के रूप में चार्ल्स ने सुझाव दिया है, तो निम्न

$ git am -3 --ignore-whitespace /c/temp/git/format_since_origin.patch Applying: patch 1 Applying: patch 2 Applying: patch 3

अब साथ काम करता है - अगर मैं Git diff की कोशिश, मैं नीचे के रूप में त्रुटि मिलती है।

$ git diff -p origin > ../dif_origin.patch

लागू करने पर,

$ git apply --ignore-whitespace --inaccurate-eof /c/temp/git/dif_origin.patch
c:/temp/git/dif_origin.patch:9: trailing whitespace.
patch change for file1.c
c:/temp/git/dif_origin.patch:18: trailing whitespace.
patch this xml guy
c:/temp/git/dif_origin.patch:29: trailing whitespace.
fsdfsd
c:/temp/git/dif_origin.patch:30: trailing whitespace.
patch this report
error: patch failed: file1.c:6
error: file1.c: patch does not apply
error: patch failed: file1.xml:2
error: file1.xml: patch does not apply
error: patch failed: tr/test_report.txt:2
error: tr/test_report.txt: patch does not apply

+0

क्या कोई कारण नहीं है कि 'गिट बंडल' या यहां तक ​​कि 'गिट diff'/'git apply' का उपयोग न करें? –

+0

@charles, मुझे गिट diff का उपयोग करने और लागू करने पर त्रुटियां मिलती हैं। मैंने मूल पोस्ट में त्रुटि विवरण जोड़ा है। क्या मैंने अंतर गलत बनाया? – maxmelbin

उत्तर

13

ध्यान दें कि खाली स्थान के अनदेखी करने के लिए होने के लिए एक तर्क था (June 2010):

What it does is enable the GMail -> download -> git-am workflow .
GMail (and doubtless countless other) E-Mail providers introduce whitespace at the beginning of raw E-Mail messages, while otherwise leaving them intact.

"git am/format-patch: control format of line endings" में उल्लेख किया है, आप एक कोशिश कर सकते हैं:

git am --keep-cr 

है कि आप की आवश्यकता नहीं होगी व्हाइटस्पेस को अनदेखा करने के लिए (केवल चेतावनी)।

OP maxmelbinin the comments पुष्टि करता है कि निम्न काम करता है:

git am -3 --keep-cr --committer-date-is-author-date /c/temp/git/format_since_origin.patch 
7

ठीक। निम्नलिखित काम किया।

$ git am -3 --ignore-whitespace /c/temp/git/format_since_origin.patch
Applying: patch 1
Applying: patch 2
Applying: patch 3

आवेदन करते समय मुझे व्हाइटस्पेस को अनदेखा करने की आवश्यकता क्यों होगी?

+1

वॉनसी उत्तर के अनुसार, निम्नलिखित भी एक ही SHA1 - git am -3 --keep-cr --committer-date-is-author-date /c/temp/git/format_since_origin.patch – maxmelbin

10

जब Git लागू सामान्य रूप से काम कर रहा है, तो आप कोई उत्पादन बिल्कुल मिलती है:

$ git apply example.patch 
[nothing returned] 

आप को देखने के लिए क्या के पीछे चल रहा है चाहते हैं दृश्य, आप -v (verbose) ध्वज का उपयोग कर सकते हैं:

$ git apply -v example.patch 
Checking patch includes/common.inc... 
Applied patch includes/common.inc cleanly. 

हालांकि, यदि चलने वाली गिट आपके स्थानीय गिट कामकाजी प्रतिलिपि से लागू होती है, तो यह संभव है कि -v (verbose) ध्वज के साथ भी, गिट लागू कुछ भी नहीं करेगा, और कोई आउटपुट नहीं देगा। यदि ऐसा होता है, तो कृपया निर्देशिका पेड़ में अपना स्थान देखें - गिट आवेदन किसी अन्य स्थान से काम कर सकता है।

$ patch -p1 < example.patch 

यहाँ अन्य उत्पादन Git लागू आदेश उत्पन्न कर सकते हैं, और क्या यह मतलब है:

एक वैकल्पिक git लागू करने के लिए पैच आदेश का उपयोग करने के लिए है। पैच लागू नहीं होता

$ git apply example.patch 
error: patch failed: includes/common.inc:626 
error: includes/common.inc: patch does not apply`` 

Git पैच में परिवर्तनों को लागू नहीं कर सकता है, क्योंकि यह प्रश्न में कोड की पंक्ति (रों) ढूँढने में सक्षम नहीं था, उन्हें किसी अन्य प्रतिबद्धता से बदला या हटा दिया जाना चाहिए। इन चीजों को आजमाएं:

सुनिश्चित करें कि पैच पहले से ही लागू नहीं किया गया है। गिट-लॉग में इसकी तलाश करें या यह देखने के लिए कोड की जांच करें कि क्या परिवर्तन पहले से मौजूद हैं या नहीं। यदि वे हैं, तो आप कर चुके हैं। यदि वे नहीं हैं या उनमें से केवल कुछ हैं, तो कुछ और कोशिश करें:

patch -p1 < filename.patch का उपयोग करें। जबकि गिट-लागू पूरी तरह से किसी भी त्रुटि के साथ पैच को अस्वीकार करता है, पैच-पी 1 हंक द्वारा हंक काम करता है, जितना संभव हो उतना व्यक्तिगत परिवर्तन लागू करता है। यह प्रत्येक फ़ाइल को filename.ext.orig के रूप में संशोधित करने से पहले बैक अप करता है और filename.ext.rej में अस्वीकृत शिकारी बचाता है। .orig फ़ाइलों को छोड़ दें और .rej में छोड़े गए परिवर्तनों को मैन्युअल रूप से लागू करें। छोटे पैच के लिए यह एक आसान रणनीति है।

+4

'patch -p1 उत्पन्न करेगा mdesantis

संबंधित मुद्दे