8000 Deleting git tag or branch deletes ancestors and breaks `jj undo` · Issue #6325 · jj-vcs/jj · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wgslr opened this issue Apr 12, 2025 · 3 comments
Open

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

wgslr opened this issue Apr 12, 2025 · 3 comments

Comments

@wgslr
Copy link
wgslr commented Apr 12, 2025

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
@yuja
Copy link
Contributor
yuja commented Apr 12, 2025

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.

Maybe you know, but it's by design. In colocated repos, commits that become unreachable at git side are imported (= abandoned.) You can turn off this behavior by config:

https://jj-vcs.github.io/jj/latest/config/#abandon-commits-that-became-unreachable-in-git

And even jj undo does not restore them.

Minor correction: undo works for branch/bookmark deletion. It doesn't work for tags, though.

The whole problem is that jj doesn't have tag management functions yet, so any tag changes in Git are imported (no matter if they were previously observed and had been imported.)

@wgslr
Copy link
Author
wgslr commented Apr 12, 2025

Maybe you know, but it's by design. In colocated repos, commits that become unreachable at git side are imported (= abandoned.) You can turn off this behavior by config:

https://jj-vcs.github.io/jj/latest/config/#abandon-commits-that-became-unreachable-in-git

Ah, I did not know! Thanks a lot for the pointer, I'll change the setting.

Minor correction: undo works for branch/bookmark deletion. It doesn't work for tags, though.

I'm fine with the tag itself not being recover 7F88 ed but I'd like to get the abandoned commits back. As it is now, I was both surprised that the tag deletion has such a big impact, and to recover the lost work I had to look for git commit hashes in jj op log -d.
I'd argue this is a very unintuitive behavior, as it is the first time I encounter a situation where jj undo does not actually bring the repo to the earlier state - the abandoned commits are still gone after I undid the "import git refs" operation which made them disappear. It was surprising after getting used to the fact that "snapshot working copy" operation can be easily undone - and this feels similar, as jj learning about changes happening outside of it.

@yuja
Copy link
Contributor
yuja commented Apr 12, 2025

Minor correction: undo works for branch/bookmark deletion. It doesn't work for tags, though.

I'm fine with the tag itself not being recovered but I'd like to get the abandoned commits back. As it is now, I was both surprised that the tag deletion has such a big impact, and to recover the lost work I had to look for git commit hashes in jj op log -d.

I kind of agree. I just tried to explain why the commits abandoned by tag deletion couldn't be recovered (or to be more precise, re-abandoned after jj undo.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0