0

So, the simplest way to ask my question, as far as I can tell, is to specify my use-case. At the end of the day, when I write in my journal, I want to be able to see what I have done that day. So I fetch changes from work and then look at the log to remember what I did. The problem here is that even though clones allegedly contain everything important, I cannot for the life of me get the log entries of newer commits without checking out the branch in question and possibly doing a fast-forward. This can be done with SourceTree and TortoiseGit, but I use Linux, and all of the tools I have tried have the same issue as the stock git log --all command that doesn't list the new commits that I know are there. How can I do this WITHOUT checking out all of the branches that may have new commits?

Edit: since giving replies in a comment is limited, I will do it here.

  • I am currently using a bare repo with worktrees around it. Don't think that would cause issues, but I am including that anyway. The format is
  • -Code
  • ---Code.git
  • ---master
  • git branch -r outputs nothing when in Code.git and master. It gives a "not a git repo" error in Code
  • git fetch --all indicates that it is fetching and receiving objects. It also completes successfully.
  • git remote -vv outputs the origin remote for push and fetch
  • git ls-remote origin shows all refs and branches on the remote
  • Code.git/packed-refs contains a list of refs for heads and tags for the remote
  • find Code.git/refs outputs:
refs/
refs/heads
refs/heads/master
refs/tags
BrainStorm.exe
  • 1,565
  • 3
  • 23
  • 40
  • 3
    `git log --all` definitely shows all commits. Maybe not in the order in which you expect them, but it shows all commits. – knittl Mar 18 '21 at 06:53
  • What is your working directory when you run `git branch -r`? Try running it in `Code`, in `Code.git`, and in `master`. Kindly provide the output from each directory. – knittl Mar 19 '21 at 05:53
  • But it sounds like "worktrees" is the magic word here which was missing from the original question. – knittl Mar 19 '21 at 05:54

1 Answers1

3

To view commits of remote-tracking branches specify their name (assuming a remote named origin; which is the default):

git log origin/branch1 origin/branch2

If only interested in new commits on a branch since your current commit:

git log HEAD..origin/branch1

If you want to view all history excluding a specific commit, you can use negative refs:

git log --all ^HEAD
# or more explicit:
git log --all --not HEAD

Make sure that your remotes are configured correctly. They must contain a fetch option in the .git/config file, otherwise no remote-tracking branches will be created nor updated in your repository. Usually, a remote block in the config file looks like this:

[remote "origin"]
    url = git://git.kernel.org/pub/scm/git/git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
knittl
  • 246,190
  • 53
  • 318
  • 364
  • Specifying things like that gives me something like `fatal: ambiguous argument 'origin/bug52339': unknown revision or path not in the working tree.` – BrainStorm.exe Mar 18 '21 at 06:59
  • 2
    @BrainStorm.exe but all remote branches have been fetched successfully? What branches are shown when you run `git branch -r`? – knittl Mar 18 '21 at 07:01
  • Nothing... Even after a `git fetch --all`. And, yes, the fetch did succeed. – BrainStorm.exe Mar 18 '21 at 23:54
  • @BrainStorm.exe `git branch -r` outputs nothing? Are you sure a) your repository is a clone (`git fetch --all` outputs nothing for non-clones) b) you have a remote configured `git remote -vv` c) the remote contains branches `git ls-remote origin` d) the fetch really succeeded (printing something like "Receiving objects"? Do you see the remote branches in `.git/packed-refs` or in `.git/refs/remotes/*/`? – knittl Mar 19 '21 at 05:31
  • Updated question with answers – BrainStorm.exe Mar 19 '21 at 05:48
  • Updated the `git branch -r` item. Sorry I didn't have "worktrees" in the original question. – BrainStorm.exe Mar 19 '21 at 05:58
  • @BrainStorm.exe Please run `git branch -r` in one of your worktrees and in the bare repo – knittl Mar 19 '21 at 06:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230109/discussion-between-brainstorm-exe-and-knittl). – BrainStorm.exe Mar 19 '21 at 06:15