When patching what’s the difference between arguments -p0 and -p1
patch
What's the difference between patch -p0 and patch -p1?
Is there any difference at all?
Best Answer
The most common way to create a patch is to run the diff command or some version control's built-in diff-like command. Sometimes, you're just comparing two files, and you run diff like this:
Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:
patch <alice_to_bob.patch version2_by_alice.txt
Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of diff looks like this:
diff -ru old_version new_version >some.patch
Then the patch contains file names, given in header lines like diff -ru old_version/dir/file new_version/dir/file. You need to tell patch to strip the prefix (old_version or new_version) from the file name. That's what -p1 means: strip one level of directory.
Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example cvs diff produces header lines that look like diff -r1.42 foo. Then there is no prefix to strip, so you must specify -p0.
In the special case when there are no subdirectories in the trees that you're comparing, no -p option is necessary: patch will discard all the directory part of the file names. But most of the time, you do need either -p0 or -p1, depending on how the patch was produced.
The patch is failing because the other patches that you have previously applied have shifted the code around sufficiently to defeat patch's attempts to apply the change, even with an offset (as can be seen in those hunks that did succeed).
If you open dwm.c.rej you will see the failed hunks, then it is just a matter of hand patching them in to dwm.c.
For each failed hunk, search in dwm.c for the original code (the lines that begin with a - in dwm.c.rej) and replace them with the patched code (those lines beginning with a +). If dwm recompiles without error, you have successfully patched in transparency.
It's a patch that undoes the earlier patch. It can be made with patch -R -pX bad.patch (where X is the number of directory levels to strip from the patch and bad.patch is the patch we want to undo) followed by a git commit
A "reversed patch" is when someone accidentally makes a patch with diff -u foo.c foo.c.orig (where foo.c is the newer file) instead of the correct diff -u foo.c.orig foo.c
The "reversed or previous applied patch" error indicates the patch has already been applied. I can not be more specific without knowing the contents of your kernelsuspend.patch file.
If you have the .git directory for the kernel source, you can look at the log for a single file with the git log command followed by the file name. e.g. git log fs/eventpoll.c or even git log -p fs/eventpoll.c.
Best Answer
The most common way to create a patch is to run the
diff
command or some version control's built-indiff
-like command. Sometimes, you're just comparing two files, and you rundiff
like this:Then you get a patch that contains changes for one file and doesn't contain a file name at all. When you apply that patch, you need to specify which file you want to apply it to:
Often, you're comparing two versions of a whole multi-file project contained in a directory. A typical invocation of
diff
looks like this:Then the patch contains file names, given in header lines like
diff -ru old_version/dir/file new_version/dir/file
. You need to tellpatch
to strip the prefix (old_version
ornew_version
) from the file name. That's what-p1
means: strip one level of directory.Sometimes, the header lines in the patch contain the file name directly with no lead-up. This is common with version control systems; for example
cvs diff
produces header lines that look likediff -r1.42 foo
. Then there is no prefix to strip, so you must specify-p0
.In the special case when there are no subdirectories in the trees that you're comparing, no
-p
option is necessary:patch
will discard all the directory part of the file names. But most of the time, you do need either-p0
or-p1
, depending on how the patch was produced.