code

IntelliJ를 사용하여 두 개의 임의 파일 비교

codestyles 2020. 12. 14. 08:12
반응형

IntelliJ를 사용하여 두 개의 임의 파일 비교


IntelliJ diff 도구가 정말 마음에 듭니다. 이 도구를 사용하여 두 개의 임의 파일을 비교할 수 있는지 궁금합니다. 즉 IntelliJ 프로젝트에없는 파일입니다. 파일 시스템에서 두 개의 파일을 선택하고 비교 하시겠습니까? 두 개의 문자열을 비교하려면 어떻게해야합니까? 텍스트 편집기에서 두 개의 새 문서를 만들고 텍스트를 붙여넣고 비교 한 다음 완료되면 파일을 저장하지 않습니다. 이것이 가능한가?

감사


다음 명령 줄을 찾았습니다.

MacOSX : (IDEA EAP 11)

/Applications/IntelliJ\ IDEA\ 11.app/Contents/MacOS/idea diff /Users/ben75/file1.txt /Users/ben75/file2.txt

MacOSX에서는 IDEA (11)가 열려있을 때 실행할 수 없습니다.

Windows : (IDEA EAP 12)

"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.0\bin\idea.exe" diff C:\Users\ben75\file1.txt C:\Users\ben75\file2.txt

IDEA가 이미 열려 있어도 실행됩니다.

확장자가없는 파일 (또는 일치하지 않는 확장자)을 비교할 때 문제가 있습니다.

IDEA에서 직접 (EAP 12)

그렇게 쉽지는 않지만 작동합니다 ...

  • 파일> 열기 ...> "file1.txt"선택
  • 파일> 열기 ...> "file2.txt"선택
  • "즐겨 찾기 목록"을 만들고 두 파일을이 즐겨 찾기 목록에 추가합니다. (이 작업을 수행하려면 : 편집기에서 파일 이름 탭을 ctrl + 오른쪽 클릭> 즐겨 찾기에 추가> 방금 만든 즐겨 찾기 목록 선택-스크린 샷 참조)
  • 마지막으로 "즐겨 찾기"보기를 ​​엽니 다 (Alt + 2 또는 왼쪽 또는 IDEA 창에서 클릭).
  • 두 파일 모두 선택
  • 오른쪽 클릭 : "두 파일 비교"(또는 Ctrl + D)

즐겨 찾기에 추가


IntelliJ Idea 13에는 Compare with Clipboard 라는 기능이 있습니다. 이 기능은 현재 열려있는 파일을 클립 보드에 복사 한 버전과 비교합니다. 두 파일을 쉽게 비교하고 병합 할 수있는 훌륭하고 쉬운 방법입니다. 또한 두 개의 임의의 코드 블록을 비교하는 데 사용할 수도 있습니다. 한 블록이 작동하고 다른 블록이 작동하지 않는 이유를 알 수 없습니까? 이 기능을 사용하십시오.

이 옵션은 보기> 클립 보드와 비교 아래에 있습니다. 이 기능에 빠르게 액세스 할 수 있도록 기억하기 쉬운 키보드 단축키를 지정했습니다.

보기> 클립 보드와 비교


프로젝트 패널 에서 2 개의 파일을 선택 하고 +를 누릅니다CTRLD .

여기에 이미지 설명 입력


2018.2 이후 IntelliJ는 공식적으로 지원했습니다 .

Windows의 경우 : Ctrl + Shift + A를 누른 다음 "Open Blank Diff Window"를 입력합니다.

여기에 이미지 설명 입력

여기에 이미지 설명 입력

Mac의 경우 : Cmd + Shift + A를 누른 다음 "Open Blank Diff Window"를 입력합니다.

여기에 이미지 설명 입력

여기에 이미지 설명 입력


터미널에서 다음과 같이 아이디어 실행기를 직접 사용할 수 있습니다.

# Windows
idea.exe diff path1 path2

# MacOS/Linux
idea diff path1 path2

적어도 MacOS의 경우 (Windows는 확실하지 않음) "도구-> 명령 줄 실행기 만들기 ..."를 통해 명령 줄 실행기를 만든 경우 다음과 같이 간단합니다.

# Create some files to diff
echo "This is line 1" > file1.txt
echo "This is line 2" > file2.txt

# Diff with IntelliJ
idea diff file1.txt file2.txt

Note this works with other JetBrains applications as well; for example, using WebStorm or PyCharm:

# Diff with WebStorm
webstorm diff file1.txt file2.txt
# Diff with PyCharm
charm diff file1.txt file2.txt

Reference


Yes you can (of course, if we are talking about text files). But probably you will need to create some project (just for opening there files).

Then your steps will be:

1) Add to created project file#1 and file#2.

2) Open file#1 in editor

3) Right click mouse in left menu (project files browser) on file#2 and find menu-item Compare File with Editor.

여기에 이미지 설명 입력

That's all. After p.3) a comparison windows will be opened.


In IntelliJ IDEA 2018.2, you can open an empty Differences Viewer and paste any text you want to compare in its left and right panels. The new Open Blank Diff Viewer action can be found in the Find Action dialog.


In order to compare two files that both aren't in the project, the following works for me in IntelliJ IDEA Ultimate 14.1.7 on Windows:

  1. Open the first file in the IDE (either by dragging from Windows Explorer into the window, or by File / Open).
  2. In the view menu, choose "Compare With…"
  3. In the "Select Path" dialog that appears, select the second file (either directly, or by dragging from Windows Explorer into the dialog).

It then opens up in the traditional file comparison pane. If you try to edit one of the files, it presents the usual "Are you sure you want to edit a file that's not in your project" dialog, which one can accept if that's what one is trying to do.


Just select both files in project structure and hit:

Windows: ctrl+D

Mac: command+D

참고 URL : https://stackoverflow.com/questions/14386488/using-intellij-to-diff-two-arbitrary-files

반응형