jamesdlin
jamesdlin

Reputation: 89926

How should I clean up files and directories created by `git update-ref`?

If I use git update-ref to create a ref, in some cases git update-ref -d does not seem to let me clean up after it.

Example #1

git update-ref -d does not let me delete refs outside of .git/refs/:

$ git update-ref foo HEAD
$ cat .git/foo
2245ac4343404174f5063821925a7d49747df622
$ git update-ref -d foo
error: refusing to update ref with bad name 'foo'

Example #2

git update-ref -d does not remove a now-empty refs/subdirectory:

$ git update-ref refs/foo/bar/baz HEAD
$ git update-ref -d refs/foo/bar/baz
$ ls -a .git/refs/foo
./      ../

Do I need to remove .git/foo and .git/refs/foo manually (e.g. with rm and rmdir, respectively)?

Upvotes: 0

Views: 242

Answers (1)

bk2204
bk2204

Reputation: 76409

Except for special refs, such as HEAD, all refs should start with refs/, and therefore you should always specify a fully qualified reference name to git update-ref. This is a plumbing command and therefore it assumes you know how to use it properly.

In this particular case, you can delete the bad ref you created with rm, but in general you should avoid creating such refs in the first place.

As for the extra directory, it is harmless, and need not be cleaned up. You can ignore it.

Note that not all refs are stored in individual files and so you should prefer to use git update-ref or a similar Git command. Upstream is considering adding support for the reftable format and so it may not be the case that refs exist in individual files at all in some repositories.

Upvotes: 1

Related Questions