2012-09-20 4 views
2

병합해야하는 로컬 파일이 2 개 있습니다. 어느 쪽도 git에서 버전이 지정되지 않습니다. 파일을 병합하는 Linux 명령이 있습니까? merge을 시도했지만 유용한 결과를 얻지 못했습니다. 내가 보여, 자식 스타일 mergefile을 만들 찾고병합 로컬 파일

가 명확하게

$ cat m1 
hello there 
my friend 
how are you 
$ 
$ cat m2 
hello there 
my chum 
how are you 
$ 
$ merge merge m1 m2 
$ cat merge 
<<<<<<< merge 
======= 
hello there 
my chum 
how are you 
>>>>>>> m2 

편집 : mergefile 전체 첫 번째 파일이 삭제되고 두 번째 파일은 전체 출력 것을 보여 듯 파일의 차이점 인라인, 단순히

답변

3

, 나는 정말 멋진 병합 도구입니다 KDiff3을 추천 할 수 있습니다 :

는이 스크립트를 사용하여 중복 행을 포함하지 않으려면. 귀하의 경우,

kdiff3 -o output.txt m1 m2 

를 실행하고 각각에 대해

kdiff3 screenshot

이 (또는 둘 다) 선택할 수있는 라인을 선택하는 충돌을 눌러 A 또는 B 버튼을 병합 얻을 것이다. 하단 영역에서 원하는대로 편집 할 수 있습니다.


업데이트 : 터미널에서 텍스트 모드로 작업하려면 임시 저장소를 설정하는 것이 좋습니다. 자식 사용법을 배우려면 약간의 노력이 필요하지만 수행 가능합니다. 귀하의 경우 다음 명령을 사용하여 작업을 완료하게됩니다.

$ mkdir /tmp/test 
$ cd /tmp/test 
$ git init 
Initialized empty Git repository in /tmp/test/.git/ 
$ touch gitfile 
$ git add gitfile 
$ git commit -m "initial commit" 
[master (root-commit) 31efd12] initial commit 
0 files changed 
create mode 100644 gitfile 
$ git checkout -b m1-branch 
Switched to a new branch 'm1-branch' 
$ cat m1 >> gitfile 
$ git add gitfile 
$ git commit -m "m1 content" 
[m1-branch 420b423] m1 content 
1 file changed, 3 insertions(+) 
$ git checkout -b m2-branch master 
Switched to a new branch 'm2-branch' 
$ cat m2 >> gitfile 
$ git add gitfile 
$ git commit -m "m2 content" 
[m2-branch c4c525a] m2 content 
1 file changed, 3 insertions(+) 
$ git checkout master 
Switched to branch 'master' 
$ git merge m1-branch m2-branch 
Fast-forwarding to: m1-branch 
Trying simple merge with m2-branch 
Simple merge did not work, trying automatic merge. 
Auto-merging gitfile 
ERROR: content conflict in gitfile 
fatal: merge program failed 
Automatic merge failed; fix conflicts and then commit the result. 
$ cat gitfile 
hello there 
<<<<<<< .merge_file_qRmZJF 
my friend 
======= 
my chum 
>>>>>>> .merge_file_BUlXHH 
how are you 
$ 
0

새 폴더에있는 파일을 넣어 (어쨌든 코드가 작동하지 않는) 끝으로 종료하고 시도이 개 파일을 함께 접착 이상의

cat * >> output.txt 

디렉토리에있는 파일을 서로에 추가하여 output.txt에 넣습니다.

선을 복제하지 않는 정교한 버전을 원할 경우 (이 버전을 지정하지 않은 경우)이 버전은 너무 간단합니다. . 당신이 그래픽 응용 프로그램을 사용하여 괜찮다면

perl -nle 'print if ! $seen{$_}++;' m1 m2 > noduplicatelines.txt 
+0

답변 해 주셔서 감사합니다. 위의 편집을 참조하십시오. – ewok