UP | HOME
Sachin Patil

Sachin Patil

Free Software Developer | GNU Emacs Hacker

[Notes] diff & patch
Published on Mar 21, 2017 by Sachin.

diff

diff setup.py setup_mod.py -u > setup_py_with_path.diff

patch

 1: diff -u > setup.diff
 2: 
 3: patch --dry-run < setup.diff
 4: patch --dry-run < setup.diff --verbose
 5: 
 6: # Target file
 7: patch --dry-run setup.py < setup.diff
 8: patch --dry-run setup.py < setup.diff --verbose
 9: 
10: patch --dry-run < setup_py_with_path.diff
11: patch --dry-run setup.py < setup_py_with_path.diff
12: patch -p5 --dry-run < setup_py_with_path.diff
13: 
14: patch --dry-run < setup_py_with_path.diff  # will fail with an error
15: patch --dry-run swift/setup.py < setup_py_with_path.diff
16: patch -p4 --dry-run < setup_py_with_path.diff

git diff

1: git diff
2: git diff -u -p
3: git diff > my_patch.diff
4: 
5: git commit # will fail with an error
6: git add -u
7: for f in `git ls-files --modified`; do git add $f; done
8: git commit

git format-patch

 1: git format-patch
 2: git format-patch HEAD^
 3: 
 4: git format-patch -o patches/ HEAD^
 5: 
 6: git format-patch -o patches/ -3 HEAD
 7: 
 8: git format-patch -o patches/ -3 <commit-hash>
 9: 
10: git format-patch --subject-prefix="RFC" -o patches/ -3

git send-email

1: git send-email --to=psachin@redhat.com -o patches/*
2: 
3: git send-email --to=psachin@redhat.com -1