Git log after git fetch
Asked Answered
A

3

5

How can I get the same result of git log after git fetch, as I get after git pull?

I have cloned two the same repositories. Just clone for first one and with --bare flag for second one. Some time later I've executed git pull for first repository and git fetch for second one.

If I try to check git log for repositories, I get different results.

cd ~/first
git pull
git log --all --oneline | wc -l
21962

cd ~/second.git
# second
git fetch
git log FETCH_HEAD --all --oneline | wc -l
21903
Asteriated answered 4/11, 2015 at 15:27 Comment(2)
Can you detail what the differences are between these logs?Estellestella
Why are you specifying FETCH_HEAD in the second log command instead using the same command for both? You are already using --all.Roadwork
R
6

From the git-log manpage:

--all
    Pretend as if all the refs in refs/ are listed on the command line as <commit>.

Using --all, git log will look at all of the heads (local branches), remote branches, and tags, and show log entries for everything in the graph that is reachable from any of those references.

If you have done a git fetch on both repos (and a git pull implies a git fetch), then some of these things should be consistent between your two repos already: specifically remote branches and annotated tags.

However, other things may not be consistent. Non-annotated tags may not be shared between the two, and the local branches might differ.

In your second repo, you are using --bare. By definition you have no checkout at all there. That means you have not checked out any local branches. Your first repo may have non-shared local branches (such as topic or feature branches). If so, those could affect the log output when using --all.

Stashes are also stored under refs/. Any stashes in your first repo would affect git log as compared to the log of the second repo.

Roadwork answered 4/11, 2015 at 17:4 Comment(0)
S
1

As you can see in the documentation for git pull, a git pull is actually a git fetch followed by a git merge. Hence when you pull, your branch is advanced to HEAD whereas when you fetch it is not. You need to add a git merge after your git fetch to have the git log results be the same.

Seringapatam answered 4/11, 2015 at 15:45 Comment(2)
It doesn't work. git merge returns fatal: This operation must be run in a work treeAsteriated
@Asteriated it does work. The problem is that you're working in a bare repository. See this. You can't run a git pull in the second repository because git can't perform a git merge without having a work tree.Seringapatam
H
0

There is little bit difference in git fetch and git pull.

Git fetch is used to fetch the latest from the remote, whereas Git pull is used to fetch the content of remote and merge them with your branch.

Pull = fetch + Merge.

So, as you said fetch will only display log of your branch, however git pull will display complete log after merged with your remote changes.

hope it answered your question.

Haws answered 4/11, 2015 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.