기본적인 튜토리얼은 아래 사이트를 참조하세요.
튜토리얼은 생략하고 바로 patch하시려면 아래 내용을 따라하세요.
우선, patch의 기본 형태는 아래와 같습니다.
패치 방법에는 두 가지가 있습니다.
압축되지 않은 패치 대상인 파일들을 교체하거나, 압축된 패치 대상들을 바로 교체하는 방법입니다.
기존에 이미 압축되지 않은 패치 대상 파일들이 존재하는데 엔터만 누른다면, 제목과 같은 메세지가 출력되면서 패치가 정상적으로 이뤄지지 않습니다.
Y나 N을 눌러줘야 하는데 좀 복잡하고 귀찮습니다.
그래서 압축된 파일 자체의 내부 파일들을 patch합니다.
아래 그림은 압축된 파일을 패치한 결과입니다.
리눅스 patch 사용 예 - 성공하면 succeeded 확인 됨
성공 메세지와 패치 명령어가 보이죠?
기존의 파일들을 Reverse한다는 의미의 -R 옵션을 추가해줘야 합니다.
patch의 튜토리얼 사이트를 참고해 보면,
-R or --reverse
Replaced 보단 swapped란 단어를 사용해서 잘 이해는 안되지만;;
Patch라는게 별게 없고, 파일만 교체해 주는 것이라 만약 리눅스 GUI를 사용하신다면 관리자 계정으로 압축 해제 후 붙여넣기해도 상관 없습니다.
patch 옵션 펼치기
-b or --backup
- Make backup files. That is, when patching a file, rename or copy the original instead of removing it. When backing up a file that does not exist, an empty, unreadable backup file is created as a placeholder to represent the nonexistent file. See the -V or --version-control option for details about how backup file names are determined.
- Back up a file if the patch does not match the file exactly and if backups are not otherwise requested. This is the default unless patch is conforming to POSIX .
- Do not back up a file if the patch does not match the file exactly and if backups are not otherwise requested. This is the default if patch is conforming to POSIX .
- -B pref or --prefix=pref
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and append pref to a file name when generating its backup file name. For example, with -B /junk/ the simple backup file name for src/patch/util.c is /junk/src/patch/util.c.
- Write all files in binary mode, except for standard output and /dev/tty. When reading, disable the heuristic for transforming CRLF line endings into LF line endings. (On POSIX -conforming systems, reads and writes never transform line endings. On Windows, reads and writes do transform line endings by default, and patches should be generated by diff --binary when line endings are significant.)
- -c or --context
- Interpret the patch file as a ordinary context diff.
- -d dir or --directory=dir
- Change to the directory dir immediately, before doing anything else.
- -D define or --ifdef=define
- Use the #ifdef ... #endif construct to mark changes, with define as the differentiating symbol.
- Print the results of applying the patches without actually changing any files.
- -e or --ed
- Interpret the patch file as an ed script.
- -E or --remove-empty-files
- Remove output files that are empty after the patches have been applied. Normally this option is unnecessary, sincepatch can examine the time stamps on the header to determine whether a file should exist after patching. However, if the input is not a context diff or if patch is conforming to POSIX , patch does not remove empty patched files unless this option is given. When patch removes a file, it also attempts to remove any empty ancestor directories.
- -f or --force
- Assume that the user knows exactly what he or she is doing, and do not ask any questions. Skip patches whose headers do not say which file is to be patched; patch files even though they have the wrong version for the Prereq:line in the patch; and assume that patches are not reversed even if they look like they are. This option does not suppress commentary; use -s for that.
- -F num or --fuzz=num
- Set the maximum fuzz factor. This option only applies to diffs that have context, and causes patch to ignore up to that many lines in looking for places to install a hunk. Note that a larger fuzz factor increases the odds of a faulty patch. The default fuzz factor is 2, and it may not be set to more than the number of lines of context in the context diff, ordinarily 3.
- -g num or --get=num
- This option controls patch's actions when a file is under RCS or SCCS control, and does not exist or is read-only and matches the default version, or when a file is under ClearCase or Perforce control and does not exist. If num is positive, patch gets (or checks out) the file from the revision control system; if zero, patch ignores RCS , ClearCase, Perforce, and SCCS and does not get the file; and if negative, patch asks the user whether to get the file. The default value of this option is given by the value of the PATCH_GET environment variable if it is set; if not, the default value is zero.
- Print a summary of options and exit.
- -i patchfile or --input=patchfile
- Read the patch from patchfile. If patchfile is -, read from standard input, the default.
- -l or --ignore-whitespace
- Match patterns loosely, in case tabs or spaces have been munged in your files. Any sequence of one or more blanks in the patch file matches any sequence in the original file, and sequences of blanks at the ends of lines are ignored. Normal characters must still match exactly. Each line of the context must still match a line in the original file.
- Merge a patch file into the original files similar to merge(1). If a conflict is found, patch outputs a warning and brackets the conflict with <<<<<<< and >>>>>>> lines. A typical conflict will look like this:
<<<<<<< lines from the original file ======= lines from the patch >>>>>>>
- If there are conflicts, the user should edit the result and delete one of the alternatives. This option implies --forwardand does not take the --fuzz=num option into account.
- -n or --normal
- Interpret the patch file as a normal diff.
- -N or --forward
- Ignore patches that seem to be reversed or already applied. See also -R.
- -o outfile or --output=outfile
- Send output to outfile instead of patching files in place. Do not use this option if outfile is one of the files to be patched. When outfile is -, send output to standard output, and send any messages that would usually go to standard output to standard error.
- -pnum or --strip=num
- Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was
setting -p0 gives the entire file name unmodified, -p1 gives
without the leading slash, -p4 gives
and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d option.
- Conform more strictly to the POSIX standard, as follows.
Take the first existing file from the list (old, new, index) when intuiting file names from diff headers.
Do not remove files that are empty after patching.
Do not ask whether to get files from RCS , ClearCase, Perforce, or SCCS .
Require that all options precede the files in the command line.
Do not backup files when there is a mismatch.
- Use style word to quote output names. The word should be one of the following:
- Output names as-is.
Quote names for the shell if they contain shell metacharacters or would cause ambiguous output.
- Quote names for the shell, even if they would normally not require quoting.
Quote names as for a C language string.
Quote as with c except omit the surrounding double-quote characters.
- You can specify the default value of the --quoting-style option with the environment variable QUOTING_STYLE. If that environment variable is not set, the default value is shell.
- -r rejectfile or --reject-file=rejectfile
- Put rejects into rejectfile instead of the default .rej file. When rejectfile is -, discard rejects.
- -R or --reverse
- Assume that this patch was created with the old and new files swapped. (Yes, I'm afraid that does happen occasionally, human nature being what it is.) patch attempts to swap each hunk around before applying it. Rejects come out in the swapped format. The -R option does not work with ed diff scripts because there is too little information to reconstruct the reverse operation.
If the first hunk of a patch fails, patch reverses the hunk to see if it can be applied that way. If it can, you are asked if you want to have the -R option set. If it can't, the patch continues to be applied normally. (Note: this method cannot detect a reversed patch if it is a normal diff and if the first command is an append (i.e. it should have been a delete) since appends always succeed, due to the fact that a null context matches anywhere. Luckily, most patches add or change lines rather than delete them, so most reversed normal diffs begin with a delete, which fails, triggering the heuristic.)
- Produce reject files in the specified format (either context or unified). Without this option, rejected hunks come out in unified diff format if the input patch was of that format, otherwise in ordinary context diff form.
- -s or --silent or --quiet
- Work silently, unless an error occurs.
- -t or --batch
- Suppress questions like -f, but make some different assumptions: skip patches whose headers do not contain file names (the same as -f); skip patches for which the file has the wrong version for the Prereq: line in the patch; and assume that patches are reversed if they look like they are.
- -T or --set-time
- Set the modification and access times of patched files from time stamps given in context diff headers, assuming that the context diff headers use local time. This option is not recommended, because patches using local time cannot easily be used by people in other time zones, and because local time stamps are ambiguous when local clocks move backwards during daylight-saving time adjustments. Instead of using this option, generate patches with UTC and use the -Z or --set-utc option instead.
- -u or --unified
- Interpret the patch file as a unified context diff.
- -v or --version
- Print out patch's revision header and patch level, and exit.
- -V method or --version-control=method
- Use method to determine backup file names. The method can also be given by the PATCH_VERSION_CONTROL(or, if that's not set, the VERSION_CONTROL) environment variable, which is overridden by this option. The method does not affect whether backup files are made; it affects only the names of any backup files that are made.
The value of method is like the GNU Emacs 'version-control' variable; patch also recognizes synonyms that are more descriptive. The valid values for method are (unique abbreviations are accepted):
- existing or nil
- Make numbered backups of files that already have them, otherwise simple backups. This is the default.
- numbered or t
- Make numbered backups. The numbered backup file name for F is F.~N~ where N is the version number.
- simple or never
- Make simple backups. The -B or --prefix, -Y or --basename-prefix, and -z or --suffix options specify the simple backup file name. If none of these options are given, then a simple backup suffix is used; it is the value of theSIMPLE_BACKUP_SUFFIX environment variable if set, and is .orig otherwise.
- With numbered or simple backups, if the backup file name is too long, the backup suffix ~ is used instead; if even appending~ would make the name too long, then ~ replaces the last character of the file name.
- Output extra information about the work being done.
- -x num or --debug=num
- Set internal debugging flags of interest only to patch patchers.
- -Y pref or --basename-prefix=pref
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and prefix pref to the basename of a file name when generating its backup file name. For example, with -Y .del/ the simple backup file name for src/patch/util.c is src/patch/.del/util.c.
- -z suffix or --suffix=suffix
- Use the simple method to determine backup file names (see the -V method or --version-control method option), and use suffix as the suffix. For example, with -z - the backup file name for src/patch/util.c is src/patch/util.c-.
- -Z or --set-utc
- Set the modification and access times of patched files from time stamps given in context diff headers, assuming that the context diff headers use Coordinated Universal Time ( UTC , often known as GMT ). Also see the -T or --set-timeoption.
The -Z or --set-utc and -T or --set-time options normally refrain from setting a file's time if the file's original time does not match the time given in the patch header, or if its contents do not match the patch exactly. However, if the -f or --force option is given, the file time is set regardless.
Due to the limitations of diff output format, these options cannot update the times of files whose contents have not changed. Also, if you use these options, you should remove (e.g. with make clean) all files that depend on the patched files, so that later invocations of make do not get confused by the patched files' times.
위의 명령어를 사용하는 것은 target.patch 내부의 파일을 밖으로 끄집어 낸다는 의미이니, 명령어 입력 후에 밖으로 나온 파일들만 복사 후 붙여넣기 해도 된다는 것이죠.
참조할 다른 글
|우분투 스트리밍 서버 구현 시 참조할 사이트 (0)||2015.08.13|
|V4L2(Video For Linux 2) by Vladimir Davydov - 번역본 (0)||2015.08.12|
|linux patch file to patch : patch 적용하기 (0)||2015.08.10|
|linux - the path "" is not a valid path to the ..... kernel headers (0)||2015.07.14|
|/usr/local/bin/ffmpeg: No such file or directory (0)||2015.06.21|
|Linux에서 시간 측정, TIME 함수 사용예 (0)||2015.06.12|