Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get opposite direction of `git diff origin/master`

Tags:

git

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.

like image 228
Skeets Avatar asked Dec 13 '18 10:12

Skeets


People also ask

What does git diff origin master do?

It shows the changes between the tips of origin/HEAD and the master branches.

How do I see git diff in terminal?

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.

How do I get the diff of a file in git?

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.


1 Answers

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.

like image 110
torek Avatar answered Oct 13 '22 05:10

torek