Another way of sharing quick suggestions with your team
You are reviewing a Pull Request (PR) and you see some minor improvements or suggestions that you would like to share with the author. You might write some comments, and usually, that would be sufficient.
But imagine that in order to transmit your “whole idea” you would need to change some files because just communicating the full picture will end up in a huge comment which might be not as clear as it could be.
Well, there are multiple options. The key is to be aware of them and use them wisely depending on the priority of the task and the changes themselves:
- As already mentioned, writing a comment as feedback is a good idea by default, but not the only one.
- We can always do some pair-thinking, talk at any time. Communication is always good in order to clarify the possible uncertainty.
- Sharing your git patches is another good option.
What if you (as a reviewer) could share your idea without any single commit or comment in the PR, but sharing your changes directly with the author?
Well, that’s actually possible and really easy. As you already know, the git diff command gives you the differences between any two branches.
git diff origin develop > ../my-origin-develop.patch
What we are doing here is redirecting the output of the diff command into a file (aka: patch), so we can share that output with any other peer-team.
Well, having that patch file, it’s pretty easy to apply those changes in your local machine without doing any commit:
git apply ../my-origin-develop.patch
Applying this patch will simply change your local system in the same way the patch was created.
Let’s divide the responsibilities into two: the creator of the patch and its user:
# Checkout that branch $ ~/myProject git:(the-branch) ➜ git pull origin the-branch # Do your suggestions and changes in the targeted branch # Generate the patch file using the diff command $ ~/myProject git:(the-branch) ➜ git diff > ../your-diff.patch # Share the patch file with the author of the PR
# Ensure you are in that branch $ ~/myProject git:(the-branch) ➜ git pull origin the-branch # Apply the patch file $ ~/myProject git:(the-branch) ➜ git apply ../your-diff.patch
Originally published on https://chemaclass.medium.com/sharing-your-git-patches-9ebf648de4c6