3

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
Anton
  • 811
  • 9
  • 13

3 Answers3

5

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.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
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.

houtanb
  • 3,852
  • 20
  • 21
  • It doesn't work. `git merge` returns `fatal: This operation must be run in a work tree` – Anton Nov 05 '15 at 07:21
  • @Anton it does work. The problem is that you're working in a `bare` repository. See [this](http://stackoverflow.com/questions/11931840/getting-fatal-this-operation-must-be-run-in-a-work-tree-on-bare-repository). You can't run a `git pull` in the second repository because git can't perform a `git merge` without having a work tree. – houtanb Nov 05 '15 at 09:20
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.

Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36