If I run git diff origin/master
, it shows me the changes in my local copy of the files in the repo against the files in the master branch in the remote repository.
I know you can list another parameter, and swap the parameters to get the opposite like this:
git diff origin/branch_a origin/branch_b
becomes:
git diff origin/branch_b origin/branch_a
...but in my case, I want to compare with local (possibly uncommitted) changes.
Is there a way to do the opposite of git diff origin/master
? So basically, the output would be the same, but instead of where it says lines were removed, it would say they were added, and vice-versa.
I know I could write a script to parse the text and reverse it, but I figured there must be a way to do it and I just don't know what it is / can't find the manual page on how to do it.
When you then run git apply -R git will simply do the opposite to the patch. Using HEAD~3 creates a patch from a single commit for me.
In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.
Right: git diff commit-specifier
compares the given commit's tree to the work-tree, with the commit's tree on the "left side" as a/
and the work-tree on the "right side" as b/
. As you noted, it's tough to reverse these as the work-tree is implied by the lack of a second tree or commit specifier.
Fortunately, git diff
has a -R
option to reverse the two sides, so git diff -R commit-specifier
does the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With