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.
It shows the changes between the tips of origin/HEAD and the master branches.
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
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