git using-git-for-collaboration

Such a peek can be done with the log command. It comes in at least three variants. Without dots, with two dots and with three dots.

CommandNew filesChanged filesDeleted files
Alice/> git init
Initialized empty Git repository in /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git/
snap no: 1

Alice adds a file. Note the typo (noe instead of one).

Alice/> printf "noe\ntwo\nthree\n" > numbers.txt
snap no: 2
Alice/> git add numbers.txt
snap no: 3
Alice/> git commit numbers.txt -m "add numbers.txt"
[master (root-commit) 54925a3] add numbers.txt
 1 file changed, 3 insertions(+)
 create mode 100644 numbers.txt
snap no: 4

Bob clones Alice's repository

Bob/> git clone /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice .
Cloning into '.'...
done.
snap no: 1
.git/HEAD
.git/index
.git/config
.git/packed-refs
.git/description
.git/refs/heads/master
.git/refs/remotes/origin/HEAD
.git/info/exclude
.git/hooks/pre-rebase.sample
.git/hooks/pre-push.sample
.git/hooks/applypatch-msg.sample
.git/hooks/pre-commit.sample
.git/hooks/post-update.sample
.git/hooks/commit-msg.sample
.git/hooks/pre-applypatch.sample
.git/hooks/update.sample
.git/hooks/prepare-commit-msg.sample
.git/logs/HEAD
.git/logs/refs/heads/master
.git/logs/refs/remotes/origin/HEAD
.git/objects/ae/53cf2363580a5222ab057cb849e160fa5d9d20 [tree]
.git/objects/cb/f36f188e2f1999a8fc210780d2ece9543b5b01 [blob]
.git/objects/54/925a33cabe9e11addc822c11d96c1efc8cce2a [commit]
numbers.txt

Comparing Alice's and Bob's repositories:

Bob/> diff -rq .git /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git
Only in /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git: COMMIT_EDITMSG
Files .git/config and /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git/config differ
Files .git/index and /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git/index differ
Files .git/logs/HEAD and /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git/logs/HEAD differ
Files .git/logs/refs/heads/master and /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice/.git/logs/refs/heads/master differ
Only in .git/logs/refs: remotes
Only in .git: packed-refs
Only in .git/refs: remotes
snap no: 2

What does .git/refs/origin/HEAD contain?

Bob/> cat .git/refs/remotes/origin/HEAD
ref: refs/remotes/origin/master
snap no: 3

It contains refs/remotes/origin/master. However, such a file des not exist.

Bob/> ls .git/refs/remotes/origin/master
ls: cannot access '.git/refs/remotes/origin/master': No such file or directory
snap no: 4

Bob fixes the typo ...

Bob/> sed s/noe/one/ -i numbers.txt
snap no: 5

... and commits the changes.

Bob/> git commit numbers.txt -m "Fixed typo" 
[master aeb44f7] Fixed typo
 1 file changed, 1 insertion(+), 1 deletion(-)
snap no: 6
.git/index
.git/logs/HEAD
.git/logs/refs/heads/master
.git/refs/heads/master

In the mean time, Alice adds another number to numbers.txt ...

Alice/> echo four >> numbers.txt
snap no: 5

... and commits the change.

Alice/> git commit numbers.txt -m "add fourth number."
[master 3d05481] add fourth number.
 1 file changed, 1 insertion(+)
snap no: 6
.git/COMMIT_EDITMSG
.git/index
.git/logs/HEAD
.git/logs/refs/heads/master
.git/refs/heads/master

numbers.txt now contains four numbers, still with the typo.

Alice/> cat numbers.txt
noe
two
three
four
snap no: 7

Alice defines a remote repository to make it easier to work with Bob's repository.

Alice/> git remote add bob /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Bob
snap no: 8
.git/config

Using the fetch command, Alice can peek at what Bob changed, without merging it

Alice/> git fetch bob
From /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Bob
 * [new branch]      master     -> bob/master
snap no: 9
.git/FETCH_HEAD
.git/logs/refs/remotes/bob/master
.git/objects/4c/b29ea38f70d7c61b2a3a25b02e3bdf44905402 [blob]
.git/objects/7a/1bbd139d33412f832fa3b7057e6b1bb54aec79 [tree]
.git/objects/ae/b44f783064140a4e09f9c0691509dfb31ddccb [commit]
.git/refs/remotes/bob/master

First, Alice shows the log without dots, so every commit is shown.

Alice/> git log HEAD FETCH_HEAD
commit 3d05481a9daeae7070fe68dd37247ff18eb202b3
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:11:00 2016 +0100

    add fourth number.

commit aeb44f783064140a4e09f9c0691509dfb31ddccb
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:09:00 2016 +0100

    Fixed typo

commit 54925a33cabe9e11addc822c11d96c1efc8cce2a
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:03:00 2016 +0100

    add numbers.txt
snap no: 10

Then, she uses three dots to show the changes since Bob has cloned Alice's reposiotory.

Alice/> git log HEAD...FETCH_HEAD
commit 3d05481a9daeae7070fe68dd37247ff18eb202b3
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:11:00 2016 +0100

    add fourth number.

commit aeb44f783064140a4e09f9c0691509dfb31ddccb
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:09:00 2016 +0100

    Fixed typo
snap no: 11

Finally, she uses two dots, which shows only what Bob has commited. She also uses the -p flag for more information on the commits.

Alice/> git log -p HEAD..FETCH_HEAD
commit aeb44f783064140a4e09f9c0691509dfb31ddccb
Author: René Nyffenegger <rene.nyffenegger@adp-gmbh.ch>
Date:   Fri Jan 1 00:09:00 2016 +0100

    Fixed typo

diff --git a/numbers.txt b/numbers.txt
index cbf36f1..4cb29ea 100644
--- a/numbers.txt
+++ b/numbers.txt
@@ -1,3 +1,3 @@
-noe
+one
 two
 three
snap no: 12

Alice likes Bob's change and merges them. Instead of using git fetch followed by git merge, she could also have used git pull which would have executed those two operations in one go.

Alice/> git merge bob/master 
Auto-merging numbers.txt
Merge made by the 'recursive' strategy.
 numbers.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
snap no: 13
.git/index
.git/logs/HEAD
.git/logs/refs/heads/master
.git/refs/heads/master
numbers.txt
Alice/> git status
On branch master
nothing to commit, working directory clean
snap no: 14

The typo is fixed.

Alice/> cat numbers.txt
one
two
three
four
snap no: 15

Bob wants to fetch Alice's latest changes.

Bob/> git pull
From /home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice
   54925a3..9f02fc7  master     -> origin/master
Updating aeb44f7..9f02fc7
Fast-forward
 numbers.txt | 1 +
 1 file changed, 1 insertion(+)
snap no: 7
.git/FETCH_HEAD
.git/ORIG_HEAD
.git/logs/refs/remotes/origin/master
.git/objects/3d/05481a9daeae7070fe68dd37247ff18eb202b3 [commit]
.git/objects/65/0d89fb0fe67b862fb32d66920323de21e3c0e0 [tree]
.git/objects/9f/02fc71595d75fcce7d0d0055e216f17258f141 [commit]
.git/objects/a3/715c9d73d9ceccc57b64fbf6a5e510dc47a61a [tree]
.git/objects/c6/c8539f78075e25d92b1702af902deef97ef6b2 [blob]
.git/objects/f3/84549cbeb481e437091320de6d1f2e15e11b4a [blob]
.git/refs/remotes/origin/master
.git/index
.git/logs/HEAD
.git/logs/refs/heads/master
.git/refs/heads/master
numbers.txt

In the prior pull command, git »knew« what repository to pull it from since it stored it in »remote.origin.url« which was set in git clone.

Bob/> git config --get remote.origin.url
/home/rene/github/github/git-internals/repos/using-git-for-collaboration/Alice
snap no: 8

Finally, a demonstration that Bob has received the added number »four« from Alice.

Bob/> cat numbers.txt
one
two
three
four
snap no: 9