3

I have two cloned versions of a repo (working copies) - say A and B. Now, in B, I made changes to file filename, committed and pushed. A is untouched. Now, before pulling in A, I want to see what new changes will a pull bring in.

I tried:

git diff
git diff HEAD
git diff HEAD:filename   filename

but none of them show the diffs (blank output). How to correctly view diff between local copy and head (I checked other answers, and my understanding of them is the above, but none of them seem to work).

Note: I have recently moved from svn to git. So the way I am thinking is: A & B are just copies of same "branch". Not sure if the understanding/terminology is correct.

workwise
  • 1,003
  • 16
  • 33

1 Answers1

4

You need to fetch first, then you can look for the diffs:

cd A
git remote add B /path/to/B
git fetch B

git diff master B/master

You can see other diffs in "How can I see incoming commits in git?"


I have installed gitolite on a server. And there is a repo there, say ProjectXYZ.
Now, A and B are obtained on two different machines, using git clone user@reposerver:ProjectXYZ.git.

Then:

# on machine B
cd B/
git push -u origin master

# on machine A
cd A/
git fetch
git diff master origin/master
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hmm. A and B are on different machines. And they both are copies of (sorry - have just switched from svn to git so some terminology may be wrong!) origin/master. I am not sure what `git remote add B /path/to/B` would do and infact how to specify it. – workwise Aug 02 '14 at 08:42
  • @WorkWise are both A and B cloned from a third repo, which can act as a reference? – VonC Aug 02 '14 at 08:43
  • Hmm - so basically I have installed `gitolite` on a server. And there is a repo there, say `ProjectXYZ`. Now, A and B are obtained on two different machines, using `git clone user@reposerver:ProjectXYZ.git` – workwise Aug 02 '14 at 08:45
  • @WorkWise then you can `git push` from `B`, and `git fetch` from `A` (no need to add any more remote). The `git diff` I mention in the answer will give you the diff you want. – VonC Aug 02 '14 at 08:50
  • I did `git fetch` in A. Then `git diff master origin/master` worked. Thanks – workwise Aug 02 '14 at 08:54
  • Thanks @VonC. I learned the new `fetch` command and my understanding of `cloned copies` and branches increased. – workwise Aug 02 '14 at 08:58