My last post in 2014 ;), Working with git patches.

Git is a famous versioning tool now days, many times you git access to work directly with your remote repo but few times you dont, Patch file is to save you there.

you can work locally and commit all the changes to local repository, create patch file with your authority and send to review, reviewer will chech the code and signoff your commit to remote repo as you dont have assess.

So here are steps to work with it.

  • create patch file with last few commits, say i want to send my last 3 commits to review and apply do :
git format-patch -3 HEAD --stdout > my-last-3-commits.patch
  • Applying patch (this is for reviewer) First step is check the patch.
git apply --stat my-last-3-commits.patch

Second step is check the patch, git allows you to try it and see how troublesome is the code.

git apply --check my-last-3-commits.patch

If it didnt gave any error, you are good to go.

Now final part is to use git am rather than git apply as it allows you to sign off the commit for future reffrence.

git am --signoff < my-last-3-commits.patch

Happy coding and a happy new year 2015 :)