4

How to show refs/notes in a git log --oneline --graph --all --decorate output for remotes?

With the above command I only see my own refs/notes/foobar, but not the remote ref.

The docs don't hint any command I could possibly use for this.

musicmatze
  • 4,124
  • 7
  • 33
  • 48

4 Answers4

1

UPDATE - since comment show this is apparently unclear, I've highlighted where I answered the question.


Like most git commands, git log operates on the local repo. To see the notes that are on the remote, you need to fetch them.

You can do this manually by saying

git fetch origin refs/notes/*:refs/notes/*

You also could add this to the fetch refspec for the remote, so that it will happen automatically.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Like with above answer: This does not answer my question at all. I asked how to show the remote ref for the notes. I know how notes work, I know how to fetch them and how to push them. I want to know what state the remote repository has for my notes. Your answer, albeit completely correct, does not answer my question at all. – musicmatze Apr 28 '18 at 19:12
  • 1
    @musicmatze - Wrong. I did answer your question. The answer is "you can't". I also added information about what you can do instead. I don't actually care that you already knew that; the answers are here to be useful to anyone who might search for the same information in the future. But don't worry; I keep track of users who are rude to those who try to help them, so you won't have to worry about me "not answering" one of your questions again. – Mark Adelsberger Apr 30 '18 at 02:25
  • 1
    I'm sorry that my reply appeared to be rude to you, it was not meant to be. But no, the reply does not answer my question: With `git log --decorate` I can see remote references for branches. But I cannot see them for notes, even if the notes are fetched. So your reply does not answer my question, sorry. – musicmatze Apr 30 '18 at 20:18
  • @musicmatze - Wrong again. You cannot see remote refs for branches. You can see local refs that tell you where the remote branches were the last time you fetched. Sorry, but I did answer your question, and the answer is correct even though you don't want it to be. – Mark Adelsberger May 03 '18 at 18:23
  • You state, and I quote: "To see the notes that are on the remove, you need to fetch them". I fetched them. I do not see where the remote is on the ref/notes/foobar reference. So your answer is not correct. – musicmatze May 03 '18 at 19:13
  • @musicmatze - No, now you're changing the question to try to make my answer wrong. The answer was "you can't [see the state on the remote]", which is the one and only correct answer no matter how many times you try to make out otherwise. As to the additional info I provided (that you can see the notes once you fetch the notes), that is *also* correct. You're trying to call it incorrect because you *want* to be able to see it in a particular way (that wasn't mentioned in your question), and you're pretending to misunderstand my answer as saying you'd be able to; and with that... – Mark Adelsberger May 03 '18 at 21:35
  • @musicmatze - ... it takes your response to people trying to help you from merely "rude" to "dishonest". My engagement in this discussion is at its end. Best of luck to you. – Mark Adelsberger May 03 '18 at 21:36
1

Maybe this is more an answer to something the OP said in a comment:

I want to know what state the remote repository has for my notes.

And it does not address incorporating anything in git log's output as the original question referenced:

... in a git log --oneline --graph --all --decorate output ...

But none of the other discussion mentions ls-remote, which I find helpful for diagnosing issues in the Notes fetch/merge/push process.

E.g. I ask users to run the following when Notes don't appear to be fetching/merging/pushing correctly, showing all 3 things that are typically meant to stay in sync:

  • The first command shows what the remote has.
  • The second command shows your tracking refs for the remote. (I didn't see any reference to tracking refs here, but we've found it helpful for letting multiple people work on Notes.)
  • The third command shows your local refs.
MINGW64 ~/git/repo (master)
$ git ls-remote origin refs/notes/* && git for-each-ref refs/notes/origin/* && git for-each-ref refs/notes/*
b8a71bdc018808e3890800a452d3ac87a0f83261        refs/notes/releaseRollback
e15b2bdc0183f791fcaf1da3b80e5125f58bae9a        refs/notes/sourceCommits
b8a71bdc018808e3890800a452d3ac87a0f83261 commit refs/notes/origin/releaseRollback
e15b2bdc0183f791fcaf1da3b80e5125f58bae9a commit refs/notes/origin/sourceCommits
b8a71bdc018808e3890800a452d3ac87a0f83261 commit refs/notes/releaseRollback
e15b2bdc0183f791fcaf1da3b80e5125f58bae9a commit refs/notes/sourceCommits

You still can't see the actual values (blob contents) of the Notes on the remote, as mentioned in the other answers, because they have to be fetched, but using ls-remote means you at least have some idea of whether the remote has changed.

JKD
  • 103
  • 7
0

First of all let's explain what git notes are.

git commit

As you know every time you commit code to git, git records the current snapshot of the files and the commit object stores the tree and any other extra info as the commit metadata. This metadata is then passed to sha1sum and we get the commit id <SHA-1>.

enter image description here

If later on, we try to modify the commit git commit --amend, the sha-1 will be updated as we can see below. The content is still the same but the SHA-1 is different.

enter image description here


git notes

As explained above any modification made to commit effects the SHA-1, and this is where git notes come to rescue.

git notes allow us to add content to commit without affecting the SHA-1 of the commit, meaning we can attach content to the commit while leaving the SHA-1 unmodified.

enter image description here

As you can see, git notes is not part of the commit content and like any other commit content is stored under the .git folder (locally under refs/notes/).

In order to get the notes from the server, you have to fetch them like any other git content.

How to fetch notes?

In order to fetch the notes, use the following fetch command with the following refspec:

#  Manually fetch the notes
git fetch origin refs/notes/*:refs/notes/*

#  Add configuration to auto-fetch the notes every time you execute a simple fetch.
#  This will result in fetching the notes every time you fetch the remote.
git config --add remote.origin.fetch +refs/notes/*:refs/notes/*
Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    This does not answer my question at all. I asked how to show the remote ref for the notes. I know how notes work, I know how to fetch them and how to push them. I want to know what state the remote repository has for my notes. Your answer, albeit completely correct, does not answer my question at all. – musicmatze Apr 28 '18 at 19:10
  • 1
    Also, your suggestion to add `+refs/notes*:refs/notes/*` is dangerous, as the `+` indicates that the current state of the notes locally can (and will) be overwritten when fetching from a remote. I ran into this before. Please refrain from adding the `+` in future answers (no offense! I didn't knew this before, I do not assume you knew this!) – musicmatze Apr 28 '18 at 19:12
0

“Remote” in this context (git-log(1)) most typically means remote refs, i.e. refs/remotes/*. In other words:

git log origin/main

To see the log of the main branch belonging to the origin remote that you have fetched locally.

But those are only for branches, not other refs like notes. So there is no out-of-the-box solution for this.

The only thing you can do is fake your own remote namespace and use that:

git fetch origin refs/notes/commits:refs/notes-remotes/commits
git log notes-remotes/seed
Guildenstern
  • 2,179
  • 1
  • 17
  • 39