git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: create reflog for reflog-less ref

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 26, 2020, 02:39 UTC
Message-ID
<20200226023909.GC7911@camp.crustytoothpaste.net>
In-Reply-To
<CAOTb1wc2uMSyc7DMau2cWrWtk=_Z94+CCovORj1dGCrwgJhL=w@mail.gmail.com>
On 2020-02-26 at 01:07:35, Chris Jerdonek wrote:
Show 26 quoted lines
> Hi,
> 
> I wanted to ask on this list if there are any supported ways to create
> a reflog for an existing ref that doesn't already have a reflog.
> 
> This is more likely to come up for refs not in the standard set (i.e.
> HEAD, branches and remote-tracking branches), since reflogs aren't
> created by default for those refs.
> 
> The only workaround I could think of is using git-update-ref to delete
> the ref, and then immediately recreate it using the `--create-reflog`
> option (if that option is needed), e.g.:
> 
> $ git update-ref -d refs/foo/bar
> $ git update-ref -m "my message" --create-reflog refs/foo/bar <SHA>
> 
> This seems hacky though because it forces you to pass through a state
> where the ref no longer exists. It also requires you to get the ref's
> SHA first.
> 
> This Stack Overflow reply from 2016 suggests the idea of using `git
> update-ref -m MSG REF REF` to add lines to an existing reflog:
> https://stackoverflow.com/questions/36770141/can-i-add-a-line-to-the-reflog/36778898#36778898
> But it doesn't seem to work to create a reflog (and only seemed to
> work for me in limited circumstances otherwise, like adding to HEAD's
> reflog). (I tried with version 2.25.0.)

There is the option core.logAllRefUpdates, which has the value "always" in more modern versions of Git. The documentation says,

  If [the option is set to always, then a missing reflog is
  automatically created for any ref under refs/.

Now, that assumes that you want reflogs for all your refs, but there's really not much downside to having a reflog and not using it.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Previous: Chris JerdonekNext: Jeff King
Message 2 of 7 in “create reflog for reflog-less ref”
  1. Chris JerdonekFeb 26, 2020
  2. brian m. carlsonFeb 26, 2020
  3. Jeff KingFeb 26, 2020
  4. Chris JerdonekFeb 26, 2020
  5. Jeff KingFeb 26, 2020
  6. Chris JerdonekFeb 26, 2020
  7. Jeff KingFeb 26, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.