Home > database >  Git diff show nothing
Git diff show nothing

Time:08-13

I have a private github repo and cloned it to my local machine. I created a file tmp.tmp with some random content on my local machine, commited it and pushed into github, then I changed this file in github via github website. I see, that content in my local repo and in github is different. I typed git diff origin/main and this command showed me nothing. But git pull correctly download changes from the github.
How can I see difference between github and my local repo ? P P.S. I have a branch dev and it has a lot of differences in github and local repo. git diff origin/dev shows this differences.

CodePudding user response:

The reason you didn't see a difference is because you hadn't fetched at the time you ran the diff command. Fetch will update your remote tracking branch (origin/main) without updating your local branch. Once you pulled you fetched and also updated your local branch with the remote branch, so once again you were in sync.

Next time, issue git fetch and then run your diff to see the difference. If you like it, then you can run git merge to "pull" that into your local branch.

Here's an example diagram of the states to help visualize it. You ran the diff at "Initial" to compare main and origin/main, so you couldn't see the remote changes yet. Even after state "Pull" you still wouldn't have been able to see the diff. Only after "Fetch" would it have worked (if you hadn't pulled yet):

            main       origin/main       remote origin/main
Initial     X          X                 Y
Fetch       X          Y                 Y
Pull        Y          Y                 Y

Side Note: I rarely ever use the pull command anymore, and this is one of the reasons for it. I like to be able to see what's changed before I "pull" (actually merge) it in.

  • Related