threads / discuss / 42272

is ORIG_HEAD allowed to point to a non-existing object?

Subject: is ORIG_HEAD allowed to point to a non-existing object?

## tl;dr

2 messages between May 10, 2016 and May 10, 2016.

replies: 1people: 2as markdown or json

Christian Halstrick· May 10, 2016, 12:15 UTC · lore

If I do a "git-rebase -i ..." followed by "git reflog expire ..." and "git gc ..." then I can end up with a repo which has a ref ORIG_HEAD which points to a non-existing object.

- Is this intended?
- What's the reason to keep a ref which points to a non-existing object?
- Are there any other refs which are allowed to point to non-existing objects?
Here is how I reproduced the problem:
> git init
Initialized empty Git repository in /tmp/yy/.git/
> touch a
> git add a
> git commit -m addA
[master (root-commit) ff82f68] addA
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
> echo 2 >a
> git commit -a -m modA
[master f9ae5a7] modA
 1 file changed, 1 insertion(+)
> echo 3 >a
> git commit -a -m 'fixup! modA'
[master 271012b] fixup! modA
 1 file changed, 1 insertion(+), 1 deletion(-)
> git rebase -i --autosquash HEAD~~
[detached HEAD 3eb17d4] modA
 1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/master.
> git rev-parse --short ORIG_HEAD
271012b
> git reflog expire --expire=now --all
> git rev-parse 271012b
271012be467fcbd62a875b7187c0e9871f62ac0d
> git gc --prune=now

Counting objects: 6, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (6/6), done. Total 6 (delta 1), reused 0 (delta 0)

> git rev-parse 271012b

271012b fatal: ambiguous argument '271012b': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'

> git rev-parse --short ORIG_HEAD
271012b
Ciao
  Chris
Junio C Hamano· May 10, 2016, 18:14 UTC · re: Christian Halstrick · lore

Re: is ORIG_HEAD allowed to point to a non-existing object?

Christian Halstrick <christian.halstrick@gmail.com> writes:
Show 5 quoted lines
> If I do a "git-rebase -i ..." followed by "git reflog expire ..." and
> "git gc ..." then I can end up with a repo which has a ref ORIG_HEAD
> which points to a non-existing object.
>
> - Is this intended?
Yes.

HEAD is a ref, but other things like MERGE_HEAD, ORIG_HEAD, FETCH_HEAD are not considered as refs and they are intended to be temporary. This does mean that they will become invalid if you prune objects that are only reachable from them, but your "reflog expire && gc" falls into "if it hurts, don't do it".

← back to recent threads