Compare working area with remote (origin/master)

70 views Asked by At

I've been learning about gif diff but I'm still confused about one thing: let's say I make some changes locally. I don't want to add/commit these changes, but I would like to see the differences between my working area and the remote repo. The point is to see the differences between my local files (my Working Area) and the remote repo (origin) before merging them. I've tried this:

git fetch origin master
git diff origin/master (or just "git diff origin")

Am I doing it the right way?

1

There are 1 answers

3
knittl On BEST ANSWER

If you read the man page of git diff, you will see a list of possible ways how to call it. One of them is:

git diff [<options>] [--merge-base] <commit> [--] [<path>…​]

This form is to view the changes you have in your working tree relative to the named . You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.

So, you would simply run: git fetch; git diff origin/whatever to compare your local worktree changes relative to the named commit.


But don't be afraid to create temporary, local commits:

git commit -am 'temp'
# now compare commit with another commit, e.g. a remote one: git fetch && git diff origin/whatever HEAD
git reset HEAD^ # roll back the temporary commit

Or, if you are okay with using plumbing commands:

git add -u
# git fetch
git diff origin/whatever "$(git commit-tree -m 'temp' "$(git write-tree)")"
git  reset