Linux/patch: Difference between revisions
< Linux
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
* test # target file | * test # target file | ||
Option #1 - move to correct path manually | ==== Option #1 - move to correct path manually ==== | ||
cd ~/test ; cp test.fixed test | cd ~/test ; cp test.fixed test | ||
cd .. ; diff -u test/test.original test/test | tee test.patch | cd .. ; diff -u test/test.original test/test | tee test.patch | ||
| Line 21: | Line 21: | ||
# patching file test/test | # patching file test/test | ||
Option #2 - use the -pX to drop path components | ==== Option #2 - use the -pX to drop path components ==== | ||
cd ~/test ; cp test.fixed test | cd ~/test ; cp test.fixed test | ||
diff -u ../test/test.original ../test/test | tee test.patch | diff -u ../test/test.original ../test/test | tee test.patch | ||
| Line 33: | Line 33: | ||
# Alternative would be to edit the patch file and remove the "../" from the header | # Alternative would be to edit the patch file and remove the "../" from the header | ||
Option #3 - edit the header | ==== Option #3 - edit the header ==== | ||
cd ~/test ; cp test.fixed test | cd ~/test ; cp test.fixed test | ||
diff -u ~/test/test.original ~/test/test | tee test.patch | diff -u ~/test/test.original ~/test/test | tee test.patch | ||
Latest revision as of 16:34, 21 April 2026
patch and diff
diff from another directory
no built in method, so have to get tricky
Files for test:
- test.original
- test.fixed
- test # target file
Option #1 - move to correct path manually
cd ~/test ; cp test.fixed test cd .. ; diff -u test/test.original test/test | tee test.patch # --- test/test.original 2026-04-21 09:20:42.864135487 -0700 # +++ test/test 2026-04-21 09:20:56.014023558 -0700
# Then if could be used like: cp test/test.original test/test cat test.patch | patch -d . -p0 # patching file test/test
Option #2 - use the -pX to drop path components
cd ~/test ; cp test.fixed test diff -u ../test/test.original ../test/test | tee test.patch # --- ../test/test.original 2026-04-21 09:20:42.864135487 -0700 # +++ ../test/test 2026-04-21 09:25:49.926535912 -0700
# Then if could be used like: cp test.original test cat test.patch | patch -d .. -p1 # p1 drops first path component # patching file test/test # Alternative would be to edit the patch file and remove the "../" from the header
Option #3 - edit the header
cd ~/test ; cp test.fixed test diff -u ~/test/test.original ~/test/test | tee test.patch # --- /home/USER/test/test.original 2026-04-21 09:20:42.864135487 -0700 # +++ /home/USER/test/test 2026-04-21 09:31:31.177670259 -0700
# then edit the patch file and fix the header paths # --- test/test.original 2026-04-21 09:20:42.864135487 -0700 # +++ test/test 2026-04-21 09:31:31.177670259 -0700 cp test.original test cat test.patch | patch -d .. -p0 # patching file test/test