Programming

Windows에서 diff 패치를 어떻게 적용합니까?

procodes 2020. 7. 1. 22:04
반응형

Windows에서 diff 패치를 어떻게 적용합니까?


diff 패치를 만들 수있는 많은 프로그램이 있지만 패치를 적용하는 데 시간이 많이 걸립니다. 패치를 배포하려고하는데 사용자에게 패치를 적용하는 방법에 대한 질문이 있습니다. 그래서 나는 그것을 스스로 알아 내려고 노력했지만 단서가 없다는 것을 알았습니다. 내가 찾을 수있는 대부분의 도구는 명령 줄입니다. (명령 줄을 처리 할 수 ​​있지만, 친절하고 친근한 GUI가 없으면 많은 사람들이 길을 잃을 수 있습니다.

TortoiseSVN을 사용해 보았습니다. 적용 할 패치가 있습니다. 패치를 마우스 오른쪽 버튼으로 클릭하면 TortoiseSVN 하위 메뉴 아래에 "패치 적용"이라는 옵션이 있습니다. 빈 창을 위로 올리면됩니다.

그래서 나는 Open을 쳤다. 통합 diff를 병합하고 적용하는 두 가지 옵션이 있습니다. 패치는 운 좋게 통합 된 diff 형식입니다. 그러나 apply 옵션은 작동하지 않습니다. 패치와 폴더를 요청합니다. 어떻게 든 패치를 적용 할 파일 을 요청하는 것을 잊었습니다 ! 따라서 TortoiseSVN은 평범하지 않습니다. 패치와 파일을 가져 와서 올바르게 적용 할 수있는 Windows GUI 기반 유틸리티가 있습니까?

편집 : 지금까지 답글을 보면 Tortoise가 이미 버전이 지정된 파일 인 경우 Tortoise가 올바르게 수행하는 것 같습니다. 여기서는 그렇지 않습니다. SVN 저장소에서 나오지 않은 파일에 패치를 적용 할 수 있어야합니다. SVN이 diff를 사용하고 그것들을 만들고 적용하는 방법을 알아야한다는 것을 알기 때문에 Tortoise를 사용하려고했습니다.


패치 적용

TortoiseMerge로 :

  1. 기존 SVN repo 디렉토리를 찾아서 엽니 다.
  2. "merges"라는 새 디렉토리를 작성하십시오 (없는 경우).
  3. .patch 파일을 적용 할 파일을 복사하십시오.
  4. 다음 단계를 계속하기 전에 svn 저장소에 ADD 및 COMMIT
  5. 병합을 마우스 오른쪽 버튼으로 클릭 하고 패치 적용 ...을 선택 하십시오.
  6. 목록에서 파일을 두 번 클릭하십시오.
  7. diff가있는 패치 된 파일이 오른쪽 창에 표시됩니다
  8. 해당 분할 창을 클릭 하고 파일-> 다른 이름으로 저장 ...으로 저장 또는 내보내기를 누르 십시오 .

TortoiseMerge에서 열면 대체 스크리닝. 아래 화면에서 directory는 위의 2 단계에서 언급 한 "merges"디렉토리를 나타냅니다.선별

WinMerge GUI의 스크린 샷 : 선별


TortoiseMergeTortoiseSVN 과 함께 제공되는 별도의 유틸리티입니다.

TortoiseDiff.zip 아카이브 에서 별도로 다운로드 할 수도 있습니다 . 이렇게하면 버전이 지정되지 않은 파일에 통합 된 diff를 적용 할 수 있습니다.


나는 그것을 위해 순수한 파이썬 도구를 만들었습니다 . 교차 플랫폼 동작을 예측할 수 있습니다. 새 파일을 작성하지는 않지만 (작성시) GUI가 없지만 그래픽 도구를 작성하는 라이브러리로 사용할 수 있습니다.

업데이트 : Python이 설치되어 있으면 사용하는 것이 더 편리합니다.

pip install patch
python -m patch

GUI를 선호한다고 말했지만 명령 줄 도구가 훌륭하게 작동합니다. Windows 로의 유닉스 도구 포트에 대해서는 GnuWin참조하십시오 . 분명히 패치 명령이 필요합니다. ;-)

그래도 회선 종료에 문제가 생길 수 있습니다. GnuWin 포트는 패치 파일에 DOS 스타일 라인 종료 (CR / LF)가 있다고 가정합니다. 합리적으로 똑똑한 편집기에서 패치 파일을 열어보십시오.


TortoiseSVN에서는 패치 적용이 작동합니다. 패치는에서 작성된 디렉토리와 동일한 디렉토리에 적용해야합니다 . 이것을 명심하는 것이 항상 중요합니다. TortoiseSVN에서 수행하는 방법은 다음과 같습니다.

패치를 적용 할 폴더를 마우스 오른쪽 버튼으로 클릭하십시오. 패치 파일의 위치를 ​​묻는 대화 상자가 나타납니다. 파일을 선택하면 변경된 파일이 나열된 작은 파일 목록 창이 열리고 각 항목을 클릭하면 해당 파일에 대한 패치 작업을 나타내는 diff 창이 열립니다.

행운을 빕니다.


패치 유틸리티 의이 Win32 기본 포트를 사용할 수 있습니다 .

그것은 더 많은 다른 유틸리티와 함께 ​​제공되며 Cygwin과는 달리 DLL이나 유사한 것이 필요하지 않습니다. 원하는 작은 실행 파일을 골라 원하는 곳에 저장하십시오.

간단한 사용법 :

patch.exe -i <patchfile>

추가 도움을 받으십시오.

patch.exe --help

Git 설치의 patch.exe 유틸리티는 Windows 10에서 작동합니다.

Windows 용 Git을 설치 한 다음 "C:\Program Files\Git\usr\bin\patch.exe"명령을 사용하여 패치를 적용하십시오.

Hunk #1 FAILED at 1 (different line endings).패치를 적용하는 동안 출력 과 같은 오류 메시지 가 출력 된 경우 명령 줄에 ( -l바로 가기 --ignore-whitespace) 또는 --binary스위치를 추가해보십시오 .


EDIT: Looking at the replies so far, it seems that Tortoise will only do it right if it's a file that's already versioned. That's not the case here. I need to be able to apply a patch to a file that did not come out of an SVN repository. I just tried using Tortoise because I happen to know that SVN uses diffs and has to know how to both create them and apply them.

You can install Cygwin, then use the command-line patch tool to apply the patch. See also this Unix man page, which applies to patch.


It appears that TortoiseSVN (TortoiseMerge) requires the line Index: foobar.py in the diff/patch file. This is what I needed to do to make a non-TortoiseSVN patch file work with TortoiseSVN's right-click Apply Patch command.

Before:

--- foobar.py.org   Sat May 08 16:00:56 2010
+++ foobar.py   Sat May 08 15:47:48 2010

After:

Index: foobar.py
===================================================================
--- foobar.py
+++ foobar.py   (working copy)

Or if you know the specific revision your contributor was working from:

Index: foobar.py
===================================================================
--- foobar.py   (revision 1157)
+++ foobar.py   (working copy)

The patch tells it what file to apply to. The header should be something like (view it in Notepad or your fav text editor):

--- Folder/old_file
+++ Folder/new_file

In the case of a Subversion patch, you'd have revision numbers as well (since the file names are the same).

GNU patch will let you override those names, but I don't know of any GUI tools to do the same. I'd check with the various diff programs - though, it does not appear WinMerge supports applying patches.


Eclipse should be able to do it, go to TeamSynchronize perspective and then into Project->Apply patch


For Java projects, I have used NetBeans to apply patch files. If the Java code you are patching is not already a NetBeans project, create a project for it. To create a new project:

  • Select menu File -> New Project
  • In the resulting dialog, make it a Java Application project. Give it a name in the dialog, and click Finish.
  • Right-click the name of your project, and select Properties from the context menu
  • In the resulting dialog, select Sources, and add a Source Folder. Browse to your Java source.

Now that you have a project, apply the patch:

  • Highlight your project to select it
  • From the main menu, select menu Tools -> Apply Diff Patch
  • In the resulting dialog, browse to your patch file, select it, and press the Patch button.

That's it. Your patch should be applied, and you should see a diff window showing the changes.


If you are using Mercurial, this is done via "import". So at the command line, the hg import command, or (you may find the --no-commit option useful), or "Repository" => "Import..." in Hg Workbench.

Note that these will commit the changes by default; you can avoid this using hg import --no-commit option if using the command-line, or if you used Hg Workbench, you might find it useful to issue hg rollback after the merge.


When applying patches using TortoiseSVN, I typically save the path in the root of the checked out repository. You should then be able to right click on the patch, go to the TortoiseSVN menu, and click ApplyPatch. ApplyPatch should automatically figure out which level in the directory hierarchy the patch was created.

I have, however, had issues in the past with applying patches that contain new files, or which involve renames to files. Whatever algorithm Tortoise uses for this doesn't seem to handle those scenarios very well. Unicode can give you similar issues.


Do you have two monitors? I was having the same issue with TortoiseMerge and I realized that when I disabled one of the monitors the little window with the file list showed up. Hope this helps you.


If you are getting "Not a working copy" error message then try selecting a directory from TortoiseMerge dialog box which is a working directory of SVN.


A BusyBox port for Windows has both a diff and patch command, but they only support unified format.


I am already using BeyondCompare (commercial) for diffs and merges, and this tool also has the capability to create, view and apply patches.


I use MSYS2 from http://www.msys2.org/

It provides many utilities like patch, which, git, tree, and many more.

After installing MSYS2 simply run the package manager to install patch:

pacman -S patch

Just use:

patch -p0 < path-file.patch

remember execute this command only from the folder location where you created the patch.

참고 URL : https://stackoverflow.com/questions/517257/how-do-i-apply-a-diff-patch-on-windows

반응형