RMI-PACTA / resources

This is a place to explore and share resources. Check out the "Issues".
https://rmi-pacta.github.io/resources/
17 stars 5 forks source link

Applying commits from patch files #59

Open maurolepore opened 4 years ago

maurolepore commented 4 years ago

Based on https://mijingo.com/blog/creating-and-applying-patch-files-in-git

If branch-a has more commits than branch-b, this creates patch files under the patches directory where each patch file is a commit missing from branch-b.

git checkout branch-a
git format-patch branch-b -o patches

This will create .patch files in the patches/ directory like so:

patches/0001-a-commit-message.patch
patches/0002-another-commit-message.patch
...

Now, patch files can be emailed, and each applied anywhere like so:

git am patches/0001-a-commit-message.patch
maurolepore commented 4 years ago

For some nice variation including creating a patch file from git diff > a-file.patch and git apply a-file.patch (which leaves the changes unstaged) see https://nithinbekal.com/posts/git-patch/

maurolepore commented 4 years ago

For historical context, before GitHub and friends, git was used mostly locally and commits where shared by emailed. Back then, applying commits from patch files was common.

cc @jdhoffa 👍