Skip to content
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

git move not working as expected: deletes branches, doesn't rebase anything #911

Closed
ryan-williams opened this issue Apr 20, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@ryan-williams
Copy link

ryan-williams commented Apr 20, 2023

Description of the bug

I learned about git-branchless move from this @arxanas SO answer, but it's not working as expected.

Create empty repo, initialize as in example above
mkdir git-branchless-move-test && cd git-branchless-move-test
git init --initial-branch master
git commit --allow-empty -m A
git commit --allow-empty -m B
git branch feature
git commit --allow-empty -m F
git checkout feature
git commit --allow-empty -m C
git checkout -b feature-a
git commit --allow-empty -m D
git checkout -b feature-b feature
git commit --allow-empty -m E
git checkout feature
git branchless init --main-branch master

Verify repo state:

git log --graph --all --format=%s%d
# * E (feature-b)
# | * D (feature-a)
# |/
# * C (HEAD -> feature)
# | * F (master)
# |/
# * B
# * A

Run suggested git move command:

git move -b feature -d master

Expected behavior

Subtree rooted at "C"/feature (including "D"/feature-a and "E"/feature-b) is rebased onto "F"/master:

git log --graph --all --format=%s%d
# * E' (feature-b)
# | * D' (feature-a)
# |/
# * C' (HEAD -> feature)
# * F (master)
# * B
# * A

Actual behavior

My branches have been deleted (feature, feature-a, feature-b), and nothing has been rebased or moved, from what I can tell:

git log --graph --all --format=%s%d
# * F (HEAD -> master)
# * B
# * A

Version of rustc

No response

Automated bug report

Software version

git-branchless 0.7.0 (6c6faec-modified)

Operating system

macOS 13.1 (Darwin 22.2.0)

Command-line

/Users/ryan/.cargo/bin/git-branchless bug-report 

Environment variables

SHELL=/bin/bash
EDITOR=emacs

Git version

> git version 
git version 2.40.0

Hooks

Show 7 hooks
Hook post-applypatch
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook post-applypatch "$@"

## END BRANCHLESS CONFIG
Hook post-checkout
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook post-checkout "$@"

## END BRANCHLESS CONFIG
Hook post-commit
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook post-commit "$@"

## END BRANCHLESS CONFIG
Hook post-merge
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook post-merge "$@"

## END BRANCHLESS CONFIG
Hook post-rewrite
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook post-rewrite "$@"

## END BRANCHLESS CONFIG
Hook pre-auto-gc
#!/bin/sh
## START BRANCHLESS CONFIG

git branchless hook pre-auto-gc "$@"

## END BRANCHLESS CONFIG
Hook reference-transaction
#!/bin/sh
## START BRANCHLESS CONFIG

# Avoid canceling the reference transaction in the case that `branchless` fails
# for whatever reason.
git branchless hook reference-transaction "$@" || (
echo 'branchless: Failed to process reference transaction!'
echo 'branchless: Some events (e.g. branch updates) may have been lost.'
echo 'branchless: This is a bug. Please report it.'
)

## END BRANCHLESS CONFIG

Events

Show 5 events
Event ID: 1, transaction ID: 1 (message: move)
  1. RefUpdateEvent { timestamp: 1681996830.387656, event_tx_id: EventTransactionId(1), ref_name: ReferenceName("refs/heads/redacted-ref-0"), old_oid: a1dc7976f3acbd8daa03e26216e5c45c265083d0, new_oid: 0000000000000000000000000000000000000000, message: None }
  2. RefUpdateEvent { timestamp: 1681996830.387656, event_tx_id: EventTransactionId(1), ref_name: ReferenceName("refs/heads/redacted-ref-1"), old_oid: 8dc5c5ea575ab652149f41f8d6576988bd08bdbb, new_oid: 0000000000000000000000000000000000000000, message: None }
  3. RefUpdateEvent { timestamp: 1681996830.387656, event_tx_id: EventTransactionId(1), ref_name: ReferenceName("refs/heads/redacted-ref-2"), old_oid: 4e2f69c85f503655d7df4ecc9cb47f59caa07779, new_oid: 0000000000000000000000000000000000000000, message: None }
  4. RewriteEvent { timestamp: 1681996830.57985, event_tx_id: EventTransactionId(1), old_commit_oid: 8dc5c5ea575ab652149f41f8d6576988bd08bdbb, new_commit_oid: 0000000000000000000000000000000000000000 }
  5. RewriteEvent { timestamp: 1681996830.57985, event_tx_id: EventTransactionId(1), old_commit_oid: 4e2f69c85f503655d7df4ecc9cb47f59caa07779, new_commit_oid: 0000000000000000000000000000000000000000 }
  6. RewriteEvent { timestamp: 1681996830.57985, event_tx_id: EventTransactionId(1), old_commit_oid: a1dc7976f3acbd8daa03e26216e5c45c265083d0, new_commit_oid: 0000000000000000000000000000000000000000 }
  7. WorkingCopySnapshot { timestamp: 1681996830.599858, event_tx_id: EventTransactionId(1), head_oid: 8dc5c5ea575ab652149f41f8d6576988bd08bdbb, commit_oid: NonZeroOid(a33f73208bba12d31d48754228f319a376a0a4ec), ref_name: None }
  8. RefUpdateEvent { timestamp: 1681996830.746192, event_tx_id: EventTransactionId(1), ref_name: ReferenceName("HEAD"), old_oid: 8dc5c5ea575ab652149f41f8d6576988bd08bdbb, new_oid: 8c224301419717fd8afeb72446fd5f4c1f75742c, message: None }
:
@ 8c22430 8m (> master) x

There are no previous available events.

:
@ 8c22430 8m (> master) x

There are no previous available events.

:
@ 8c22430 8m (> master) x

There are no previous available events.

:
@ 8c22430 8m (> master) x

There are no previous available events.

:
@ 8c22430 8m (> master) x

Version of git-branchless

No response

Version of git

No response

@ryan-williams ryan-williams added the bug Something isn't working label Apr 20, 2023
@ryan-williams
Copy link
Author

ryan-williams commented Apr 20, 2023

I guess this was an artifact of my test commits being empty; git-branchless basically discards them? I get the expected result when initializing the repo with actual content in the commits:

make_commit() {
    touch "$1" && git add "$1" && git commit -m "$1"
}
git init --initial-branch master
make_commit A
make_commit B
git branch feature
make_commit F
git checkout feature
make_commit C
git checkout -b feature-a
make_commit D
git checkout -b feature-b feature
make_commit E
git checkout feature
git branchless init --main-branch master

In this case, git move -b feature -d master gives me the expected tree:

git log --graph --all --format=%s%d
# * D (feature-a)
# | * E (feature-b)
# |/  
# * C (HEAD -> feature)
# * F (master)
# * B
# * A

So I will close this. I ran into this problem while trying to minimize a different problem with git move (which may have to do with rebasing onto an unrelated history, e.g. across repositories), but I'll try to minimize+file that separately.

@ryan-williams
Copy link
Author

FWIW, I tried the original example with git move -b feature -d master --no-deduplicate-commits to try to preserve the empty commits, but it didn't work / I got the same behavior (branches deleted, structure not preserved).

@arxanas
Copy link
Owner

arxanas commented Apr 22, 2023

Under git rebase, there are a few situations in which commits will be dropped:

  • The commit is empty before being applied.
    • Git: configured with --keep-empty/--no-keep-empty.
    • git-branchless: not configurable.
  • The commit was already applied upstream, as per git cherry.
    • Git: configured with --reapply-cherry-picks/--no-reapply-cherry-picks.
    • git-branchless: configured with the --no-deduplicate-commits flag.
  • The patch was applied but the result was empty. This can happen if a set of commits were squashed upstream.
    • Git: configured with --empty={keep,drop,ask}.
    • git-branchless: not configurable.

You saw this behavior because it modeled the first situation, and that's why toggling --no-deduplicate-commits didn't affect the behavior.

@korrat
Copy link

korrat commented Jul 28, 2024

I came across this issue after encountering surprising behaviour in git move: When moving a branch with an empty HEAD commit, but other commits, the non-empty commits are moved correctly, but the branch is deleted.

@arxanas
Copy link
Owner

arxanas commented Oct 9, 2024

@korrat that might be addressable in a fix for #1205, if you want to try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants