Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docs:git:creating_and_applying_patch_files [2010/04/14 22:58] – billh | docs:git:creating_and_applying_patch_files [2014/09/29 17:09] (current) – [applying a patch file (method 2)] billh | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== creating a patch file ===== | ===== creating a patch file ===== | ||
If you are not the maintainer for a project, but still want to contribute, you can clone the repo and modify files. | If you are not the maintainer for a project, but still want to contribute, you can clone the repo and modify files. | ||
+ | |||
+ | Make sure your working copy is at the point you want as your final state. | ||
< | < | ||
git format-patch master --stdout > your-patch-file.diff | git format-patch master --stdout > your-patch-file.diff | ||
</ | </ | ||
- | ===== applying a patch file ===== | + | ===== applying a patch file (method 1) ===== |
- | First create a new branch: | + | Make sure you are on a clean working copy, then apply the patch to the working copy (no commits are added, only working copy files are updated): |
+ | < | ||
+ | git apply their-patch-file.diff | ||
+ | </ | ||
+ | |||
+ | Now you can review the changes as necessary. | ||
+ | |||
+ | Note that the above method is a git patch file, suitable for using git am. This is not the same as a standard patch file created with diff. Git patch files contain author' | ||
+ | |||
+ | ===== applying a patch file (method 2) ===== | ||
+ | This will add consecutive commits to your current branch, including the commit messages. | ||
< | < | ||
git checkout -b new-branch-name | git checkout -b new-branch-name | ||
Line 15: | Line 27: | ||
git am < their-patch-file.diff | git am < their-patch-file.diff | ||
</ | </ | ||
+ | |||
+ | Note that the above method is a git patch file, suitable for using git am. This is not the same as a standard patch file created with diff. Git patch files contain author' | ||
===== manually rewriting data for a project ===== | ===== manually rewriting data for a project ===== | ||
Line 27: | Line 41: | ||
</ | </ | ||
* edit the allcommits.patch file as necessary (change dates, commit messages, author, etc...) | * edit the allcommits.patch file as necessary (change dates, commit messages, author, etc...) | ||
+ | * to help with figuring out the correct date string used in patch files, you can use the unix date command to convert (you can add the time with similar parameters, but it is easy enough to type it by hand):< | ||
+ | date -v2m -v4d -v2008y +"%a, %d %b %Y %H:%M:%S %z" | ||
+ | </ | ||
* apply all patches< | * apply all patches< | ||
git am < allcommits.patch | git am < allcommits.patch | ||
</ | </ | ||
* also consider if [[filter-branch]] is a better alternative for your situation | * also consider if [[filter-branch]] is a better alternative for your situation |