2012-03-11 4 views
31

(प्रश्न How do I combine the two variants of a conflict in emacs' emerge? से रूपांतरित)संघर्ष समाधान: मैं दोनों संस्करणों के परिवर्तन कैसे ले जा सकते हैं

मैं मर्ज संघर्ष मार्कर के साथ एक फ़ाइल है। यह इस के समान दिखता है:

<<<<<<< HEAD 
      522ADC9C14B2FD9D00F56BAD /* close_test_button.png in Resources */, 
      522ADC9D14B2FD9D00F56BAD /* [email protected] in Resources */, 
      522ADCA014B2FDB100F56BAD /* test_failed.png in Resources */, 
      522ADCA114B2FDB100F56BAD /* [email protected] in Resources */, 
======= 
      EC1633C014B2F3E3004B52E7 /* arrow.png in Resources */, 
      EC1633C114B2F3E3004B52E7 /* [email protected] in Resources */, 
      EC1633C214B2F3E3004B52E7 /* groups.png in Resources */, 
      EC1633C314B2F3E3004B52E7 /* [email protected] in Resources */, 
>>>>>>> beta_2.8 

मैं एम एक्स VC-संकल्प-संघर्ष का उपयोग Ediff शुरू करने के लिए। मैं अपने कीबोर्ड पर एक या मारकर संस्करण एक या बी चयन कर सकते हैं, लेकिन मैं दोनों वेरिएंट, एक के बाद एक कैसे गठबंधन करते हैं?

+3

मैं इसे लंबे समय तक चाहता था, उत्साह के लिए धन्यवाद। –

उत्तर

8

आप बफर "सी" पर स्विच कर सकते हैं और इसे संपादित कर सकते हैं। + दबाएं यदि आप पहले से ही ए या बी को diff को पुनर्स्थापित करने के लिए चुना है।

यदि आप बाद में diff मार्करों को स्वचालित रूप से हटाने के लिए एक कुंजी दबाकर हैं, तो मैं केवल इतना कह सकता हूं कि यह एक भयानक विचार की तरह लगता है।

मैन्युअल विलय उपयोगकर्ता को छोड़ दिया जाना चाहिए। सुराग को दूर करने के लिए जहां प्रत्येक diff क्षेत्र आया था, मुझे सही नहीं लगता है।

एम:

(setq ediff-combination-pattern '("" A "" B "" Ancestor)) 
+9

बिंदु सिर्फ diff मार्करों को हटाने के लिए नहीं है, यह अनुरोध करना है कि दोनों परिणामों को अंतिम परिणाम में शामिल किया जाए - और लोगों को मैन्युअल रूप से ऐसा करने के लिए मजबूर करना एक पिटा है। अक्सर diff बस दिखा रहा है जहां दो लोगों ने एक सूची में चीजें जोड़ दी हैं। जाहिर है कि उपयोगकर्ता इसका चयन कर सकता है और अपना कोड तोड़ सकता है, लेकिन वे ए या बी को दबाकर ऐसा कर सकते हैं ... –

+0

यह 'कॉपी अप "या" कॉपी "जैसे सक्षम होने के लिए भी उपयोगी होगा .. – mgalgs

+0

ट्रे के साथ सहमत हैं। एक शकी को धक्का दिया जाता है क्योंकि उपयोगकर्ता कुछ करना चाहता है ..आपके तर्क से वे एडिफ को एक्सए और एक्सबी के लिए भी छोटी कटौती कुंजियों को हटा देना चाहिए ... अधिकांश अन्य सभ्य उपकरण में ए तो बी या बी लेने की क्षमता है .... यह एकमात्र कारण है जिसे मैंने कभी भी edfiff छोड़ दिया .. यह ऐसा लगता है कि इस छोटे आने के कारण विलय के लिए चूसना लगता है। – UpAndAdam

3

VC-संकल्प-संघर्ष के लिए डॉक स्ट्रिंग का कहना है कि इसके लिए एक उपनाम है

आप इस के साथ रिक्त लाइनों होने के लिए मार्कर को अनुकूलित कर सकते हैं स्मेर्ज-एडिफ़

यदि यह मेरी अपेक्षा के अनुसार काम कर रहा है, तो आपका बफर स्मरज नाबालिग मोड में होना चाहिए, और वहां स्मरज के लिए मेनू होना चाहिए। उस मेनू में आपको जो भी चाहिए वह सब कुछ है।

+4

विशेष रूप से 'सी-सी^ए' \t स्मरज-सब-सब है; _smerge-mode_ मदद देखें ... –

+0

वास्तव में 'ediff' कार्यक्षमता के लिए प्रासंगिक नहीं है (जो 'स्मेर्ज-मोड' का उपयोग नहीं करता है - या कम से कम इन दिनों, यदि यह कभी नहीं किया गया है), लेकिन निश्चित रूप से एक उपयोगी उत्तर है आप * स्मरज मोड का उपयोग कर रहे हैं। – phils

4

हाँ, मैं पूरी तरह से ऐसा करना चाहता हूं! कोड के निम्नलिखित खंड के साथ आप डी टाइप करके दोनों प्राप्त कर सकते हैं - जो आपको मर्ज बफर में 0 बफर A और बफर B (उस क्रम में) से कोड प्राप्त करेगा।

इस कोड में एकमात्र वास्तविक कठिनाई यह तथ्य है कि ediff एक स्थान पर एक मैक्रो का उपयोग करता है, और फ़ंक्शन के संकलित संस्करण को नए मैक्रो के साथ फिर से मूल्यांकन करने की आवश्यकता होती है। वैसे भी, कोड को आज़माएं। Emacs 23.2 के साथ परीक्षण किया।

(require 'ediff-init)   ;ensure the macro is defined, so we can override it 

(defmacro ediff-char-to-buftype (arg) 
    `(cond ((memq ,arg '(?a ?A)) 'A) 
    ((memq ,arg '(?b ?B)) 'B) 
    ((memq ,arg '(?c ?C)) 'C) 
    ((memq ,arg '(?d ?D)) 'D) 
    )) 

(require 'ediff) 

;; Literally copied from ediff-util 
;; need to re-evaluate because it uses the macro defined above 
;; and the compiled version needs to be re-compiled with the new definition 
;; why a macro???? 
(defun ediff-diff-to-diff (arg &optional keys) 
    "Copy buffer-X'th difference region to buffer Y \(X,Y are A, B, or C\). 
If numerical prefix argument, copy the difference specified in the arg. 
Otherwise, copy the difference given by `ediff-current-difference'. 
This command assumes it is bound to a 2-character key sequence, `ab', `ba', 
`ac', etc., which is used to determine the types of buffers to be used for 
copying difference regions. The first character in the sequence specifies 
the source buffer and the second specifies the target. 

If the second optional argument, a 2-character string, is given, use it to 
determine the source and the target buffers instead of the command keys." 
    (interactive "P") 
    (ediff-barf-if-not-control-buffer) 
    (or keys (setq keys (this-command-keys))) 
    (if (eq arg '-) (setq arg -1)) ; translate neg arg to -1 
    (if (numberp arg) (ediff-jump-to-difference arg)) 

    (let* ((key1 (aref keys 0)) 
    (key2 (aref keys 1)) 
    (char1 (ediff-event-key key1)) 
    (char2 (ediff-event-key key2)) 
    ediff-verbose-p) 
(ediff-copy-diff ediff-current-difference 
     (ediff-char-to-buftype char1) 
     (ediff-char-to-buftype char2)) 
;; recenter with rehighlighting, but no messages 
(ediff-recenter))) 

(defun ediff-copy-D-to-C (arg) 
    "Copy ARGth difference region from both buffers A and B to C. 
ARG is a prefix argument. If nil, copy the current difference region." 
    (interactive "P") 
    (ediff-diff-to-diff arg "dc")) 

(defun ediff-copy-diff (n from-buf-type to-buf-type 
       &optional batch-invocation reg-to-copy) 
    (let* ((to-buf (ediff-get-buffer to-buf-type)) 
    ;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type))) 
    (ctrl-buf ediff-control-buffer) 
    (saved-p t) 
    (three-way ediff-3way-job) 
    messg 
    ediff-verbose-p 
    reg-to-delete reg-to-delete-beg reg-to-delete-end) 

(setq reg-to-delete-beg 
     (ediff-get-diff-posn to-buf-type 'beg n ctrl-buf)) 
(setq reg-to-delete-end 
     (ediff-get-diff-posn to-buf-type 'end n ctrl-buf)) 

(if (eq from-buf-type 'D) 
    ;; want to copy *both* A and B 
    (if reg-to-copy 
    (setq from-buf-type nil) 
     (setq reg-to-copy (concat (ediff-get-region-contents n 'A ctrl-buf) 
       (ediff-get-region-contents n 'B ctrl-buf)))) 
    ;; regular code 
    (if reg-to-copy 
     (setq from-buf-type nil) 
    (setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))) 

(setq reg-to-delete (ediff-get-region-contents 
      n to-buf-type ctrl-buf 
      reg-to-delete-beg reg-to-delete-end)) 

(if (string= reg-to-delete reg-to-copy) 
    (setq saved-p nil) ; don't copy identical buffers 
    ;; seems ok to copy 
    (if (or batch-invocation (ediff-test-save-region n to-buf-type)) 
     (condition-case conds 
     (progn 
     (ediff-with-current-buffer to-buf 
      ;; to prevent flags from interfering if buffer is writable 
      (let ((inhibit-read-only (null buffer-read-only))) 

     (goto-char reg-to-delete-end) 
     (insert reg-to-copy) 

     (if (> reg-to-delete-end reg-to-delete-beg) 
      (kill-region reg-to-delete-beg reg-to-delete-end)) 
     )) 
     (or batch-invocation 
     (setq 
     messg 
     (ediff-save-diff-region n to-buf-type reg-to-delete)))) 
    (error (message "ediff-copy-diff: %s %s" 
      (car conds) 
      (mapconcat 'prin1-to-string (cdr conds) " ")) 
      (beep 1) 
      (sit-for 2) ; let the user see the error msg 
      (setq saved-p nil) 
      ))) 
) 

;; adjust state of difference in case 3-way and diff was copied ok 
(if (and saved-p three-way) 
    (ediff-set-state-of-diff-in-all-buffers n ctrl-buf)) 

(if batch-invocation 
    (ediff-clear-fine-differences n) 
    ;; If diff3 job, we should recompute fine diffs so we clear them 
    ;; before reinserting flags (and thus before ediff-recenter). 
    (if (and saved-p three-way) 
     (ediff-clear-fine-differences n)) 

    (ediff-refresh-mode-lines) 

    ;; For diff2 jobs, don't recompute fine diffs, since we know there 
    ;; aren't any. So we clear diffs after ediff-recenter. 
    (if (and saved-p (not three-way)) 
     (ediff-clear-fine-differences n)) 
    ;; Make sure that the message about saving and how to restore is seen 
    ;; by the user 
    (message "%s" messg)) 
)) 

;; add keybinding in a hook b/c the keymap isn't defined until the hook is run 
(add-hook 'ediff-keymap-setup-hook 'add-d-to-ediff-mode-map) 

(defun add-d-to-ediff-mode-map() 
    (define-key ediff-mode-map "d" 'ediff-copy-D-to-C)) 
+0

मेरा जवाब देखें - ट्रे का विचार बहुत आसान तरीके से लागू करता है। – killdash9

22

यह ट्रे जैक्सन के सहायक उत्तर के समान ही है, और यह बहुत आसान है। डी दबाकर ए और बी दोनों को बफर सी

(defun ediff-copy-both-to-C() 
    (interactive) 
    (ediff-copy-diff ediff-current-difference nil 'C nil 
        (concat 
        (ediff-get-region-contents ediff-current-difference 'A ediff-control-buffer) 
        (ediff-get-region-contents ediff-current-difference 'B ediff-control-buffer)))) 
(defun add-d-to-ediff-mode-map() (define-key ediff-mode-map "d" 'ediff-copy-both-to-C)) 
(add-hook 'ediff-keymap-setup-hook 'add-d-to-ediff-mode-map) 
+1

यह बहुत अच्छा है। पूर्णता के लिए भी त्वरित सहायता मेनू में इसके बारे में एक पंक्ति जोड़ना संभव होगा? – chengiz

+4

यह शानदार है। बफर के क्रम को स्वैप करने के लिए '~' के साथ संयुक्त आप ए * बी * या * बी फिर ए प्राप्त कर सकते हैं, जो कभी-कभी काम में आता है। –

+1

कीबाइंडिंग 'डी' कूदने के साथ विवाद के साथ संघर्ष किया। मैं इसे 'बी' (अपरकेस) के बजाय बाध्य करता हूं। – Joe

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