Skip to content

Deleting git tag or branch deletes ancestors and breaks jj undo #6325

Open
@wgslr

Description

@wgslr

Description

Deleting a tag or branch with a git command (git tag -d, git branch -d) seems to delete related commit and its ancestors in jj. And even jj undo does not restore them.

Steps to Reproduce the Problem

# create a colocated repository
$ jj git init --colocated
# create 3 commits adding 1 file each
$ touch file-1; jj new; touch file-2; jj new; touch file-3; jj new
$ jj log -r :: -s
@  xnlrnqqo wojciech.geisler@gmail.com 2025-04-12 11:39:27 6f9da7df
│  (empty) (no description set)
○  tvlzxknv wojciech.geisler@gmail.com 2025-04-12 11:39:27 git_head() 6f5f3ad1
│  (no description set)
│  A file-3
○  vmtkztlz wojciech.geisler@gmail.com 2025-04-12 11:39:25 36775ec0
│  (no description set)
│  A file-2
○  wnllnmpl wojciech.geisler@gmail.com 2025-04-12 11:39:23 65a23dbf
│  (no description set)
│  A file-1
◆  zzzzzzzz root() 00000000

# create git tag pointing to @--
$ git tag some-tag 36775
$ jj log -r :: -s
Done importing changes from the underlying Git repo.
@  xnlrnqqo wojciech.geisler@gmail.com 2025-04-12 11:39:27 6f9da7df
│  (empty) (no description set)
○  tvlzxknv wojciech.geisler@gmail.com 2025-04-12 11:39:27 git_head() 6f5f3ad1
│  (no description set)
│  A file-3
◆  vmtkztlz wojciech.geisler@gmail.com 2025-04-12 11:39:25 some-tag 36775ec0
│  (no description set)
│  A file-2
◆  wnllnmpl wojciech.geisler@gmail.com 2025-04-12 11:39:23 65a23dbf
│  (no description set)
│  A file-1
◆  zzzzzzzz root() 00000000

# delete the tag
$ git tag -d some-tag
Deleted tag 'some-tag' (was 36775ec)

# jj considers the commits abandoned and rewrites the history - surprising!
$ jj log -r :: -s
Abandoned 2 commits that are no longer reachable.
Rebased 2 descendant commits off of commits rewritten from git
Working copy  (@) now at: xnlrnqqo e48caa54 (empty) (no description set)
Parent commit (@-)      : tvlzxknv f20c24b6 (no description set)
Added 0 files, modified 0 files, removed 2 files
Done importing changes from the underlying Git repo.
@  xnlrnqqo wojciech.geisler@gmail.com 2025-04-12 11:41:22 e48caa54
│  (empty) (no description set)
○  tvlzxknv wojciech.geisler@gmail.com 2025-04-12 11:41:22 git_head() f20c24b6
│  (no description set)
│  A file-3
◆  zzzzzzzz root() 00000000

# try restoring changes
$ jj undo
Undid operation: a2b330187051 (2025-04-12 11:41:22) import git refs
Working copy  (@) now at: xnlrnqqo 6f9da7df (empty) (no description set)
Parent commit (@-)      : tvlzxknv 6f5f3ad1 (no description set)
Added 2 files, modified 0 files, removed 0 files

# file-1 and file-2 were NOT restored
$ jj log -r :: -s
@  xnlrnqqo wojciech.geisler@gmail.com 2025-04-12 11:42:05 f4a2bd1f
│  (empty) (no description set)
○  tvlzxknv wojciech.geisler@gmail.com 2025-04-12 11:42:05 git_head() 75b9d9dd
│  (no description set)
│  A file-3
◆  zzzzzzzz root() 00000000
$ ls
file-3

The same behavior is observed when creating and deleting a branch via git instead of a tag.

Expected Behavior

I expect git tag operations to have no impact on the jj tree. Especially given that there is no jj-native API for manipulating tags.

For branches, I could understand interpreting a branch removal as intent to delete the related work. And a case can be made that we should always use jj bookmark rather than git branch. However, I don't think commits should be deleted because of branch manipulation when they already have descendants.

In either case, jj undo should fully recover the lost commits.

Actual Behavior

Using git tag -d and git branch -d leads to jj behavior which cannot be recovered with jj undo.

Specifications

  • Platform: Ubuntu in WSL2
  • Version:
    • jj 0.28.2-b9ebe2f03c976515d2a155a411a368ae773c5493
    • git version 2.49.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions