Using git-format-patch
exports commits as patch files. You can then send these to your colleagues to be applied on another branched or cloned repository of the project. These patch files can contain one or more commits and Git replays that commit when you apply it.
Creating the last commit patch file
- Using terminal, change your current directory to the root directory
cd /root/directory
- Enter the following to export the last commit to a patch file
git format-patch -1 HEAD --stdout > file-name.patch
Applying the patch file
- Using terminal, change to another root directory of a branched or cloned repository
cd /other/root/directory
- Check the patch file if it would apply to the branched or cloned repository
git apply --check file-name.patch
- If there are no warnings or errors, you can apply the patch
git am --signoff < file-name.patch
- Lastly, push these changes to the branched or cloned repository
git push
Comments
Thank you a lot, you saved…
Thank you a lot, you saved my clean git history from an awful merge or to break the upstream.
Add new comment