Git: how to check what has been fetched
I am working on some stuff here. I do a few add
s, I do a couple of commit
s. Now what I am doing fetch
is to retrieve the remote changes in my remote tracking store.
How can I figure out what it is?
I know what I can do git diff origin/branch branch
to find out what is different from my remote tracking and local branch. But how can I tell what was chosen?
source to share
Difference between local and remote
If you are interested in the differences between local and remote after fetch, you can use the log commands between .git/refs/heads/
and .git/refs/remotes/origin/
or the customized upstream branches (note the use of dots versus your command):
git log ..@{u}
git log branch..origin/branch
or for extended symmetric diff:
git log --oneline --left-right --cherry-pick ...@{u}
git log --oneline --left-right --cherry-pick branch...origin/branch
What is selected
This is recorded by the command itself at runtime:
$ git fetch
(...)
From ...
c1e6a44..8f13b81 master -> origin/master
b1304b4..359293c branchA -> origin/branchA
* [new branch] branchB -> origin/branchB
Or with its verbose option ( -v
):
$ git fetch -v
(...)
From ...
c1e6a44..8f13b81 master -> origin/master
b1304b4..359293c branchA -> origin/branchA
= [up to date] branchB -> origin/branchB
+ 1e8827e...cf7aac7 branchC -> origin/branchC (forced update)
As explained in the git reference versions , this FETCH_HEAD
writes out the branch you checked out from the remote repository with the latest git fetch call:
git log ..FETCH_HEAD
However, the previous content FETCH_HEAD
is lost. Therefore, you cannot know exactly what was fetched only by the last fetch command. Try the following command (you can alias it to Git):
cp .git/FETCH_HEAD .git/FETCH_HEAD.old && git fetch -q && diff .git/FETCH_HEAD.old .git/FETCH_HEAD
Incoming changes
I often use the following alias to validate incoming changes:
in = "!git remote update -p; git log ..@{u}"
source to share
I assume you want to see what happened with origin / branch, since you checked out your branch:
I made a logging alias called 'hist': link
In this project, I typed some text into a file and created an initial commit. Then I cloned the repo and made the changes to the clone. Then I went back to origin and made changes to the file. Then I went into the copy and "took". When I type 'git hist --all' this is the output:
* 69c8726 2014-09-25 | origin change (origin/master, origin/HEAD)
| * ee54c17 2014-09-25 | change from copy (HEAD, master)
|/
* 81ba217 2014-09-25 | initial commit
To see the differences between "initial commit" and "change change", I type:
$ git diff 81ba217 origin/master
diff --git a/hello.txt b/hello.txt
index bfd905d..617496a 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1,2 @@
this is text
+this is an origin change
source to share
Using whatever git command you want to display you should use the following revision specification
@{u}@{1}..@{u}
So, for example, to list the commits you could use
git log --oneline @{u}@{1}..@{u}
To view the files that you might be using
git diff --name-only @{u}@{1}..@{u}
Or any other form or log / diff you like.
This will work for whatever tracking thread you are currently checking out for.
source to share