`git move` drops merge commits (and their descendants)
ryan-williams opened this issue · comments
Description of the bug
I need to rebase a DAG of commits (i.e. includes merge commits / is not a tree). git move
seems like the logical command to do this, but it drops merge commits and their descendants.
Is there a way to rebase a DAG of commits? If not, it seems like git move
could be made to do that.
Example repo setup
mkdir rebase-merge-test && cd rebase-merge-test
make_commit() {
touch "$1" && git add "$1" && git commit -m "$1"
}
git init --initial-branch main
git branchless init --main-branch main
make_commit A
make_commit B
git checkout -b feature HEAD^
make_commit C
git checkout -b feature-d
make_commit D
git checkout feature
make_commit E
git merge -m "Merge D and E" feature-d
make_commit F
git branch -D feature-d
git checkout -b feature-c feature~3
git log --graph --all --format=%s%d
Repo structure, pre-move
:
git log --graph --all --format=%s%d
# * F (feature)
# * Merge D and E
# |\
# | * D
# * | E
# |/
# * C (HEAD -> feature-c)
# | * B (main)
# |/
# * A
I want to move the DAG rooted at C
/feature-c
onto B
/main
, by running:
git move -s feature-c -d main
#34 says:
- On-disk rebase should either handle or abort on merge commits.
- Implemented in #93.
but merge commits don't appear to be handled or aborted on (see below; behavior is the same even if I pass--on-disk
togit move
).
Expected behavior
The DAG rooted at C
/feature-c
has been re-rooted onto B
/main
:
git log --graph --format=%s%d
# * F (HEAD -> feature)
# * Merge D and E
# |\
# | * D
# * | E
# |/
# * C (feature-c)
# * B (main)
# * A
Actual behavior
The merge-commit (Merge D and E
) and its descendent (F (feature)
) are not moved:
git log --graph --all --format=%s%d
# * E
# | * D
# |/
# * C (HEAD -> feature-c)
# * B (main)
# | * F (feature)
# | * Merge D and E
# | |\
# | | * D
# | * | E
# | |/
# | * C
# |/
# * 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
$HOME/.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: 57, transaction ID: 34 (message: post-commit)
CommitEvent { timestamp: 1682006640.0, event_tx_id: EventTransactionId(34), commit_oid: NonZeroOid(2925d3dda0ea95e6ba1da7def817ddf1f2c583d3) }
O 2b9e5e4 10m x
|\
| x 946add0 10m (rewritten as 03f978e2) x
| |\
| | x 6a5adf7 10m (rewritten as 19109bef) x
| | |
| | | & (merge) d1bd0cd 10m (rewritten as 9148ff00) x
| | |/
| | o ddb693a 10m xxxxx x xxx x
| | |
| | o 7998214 10m x
| |
| x d1bd0cd 10m (rewritten as 9148ff00) x
| & (merge) ddb693a 10m xxxxx x xxx x
|
O 7333fea 10m (main) x
|
o 03f978e 10m (redacted-ref-0) x
|\
| o 19109be 10m x
| |
| | & (merge) 9148ff0 10m x
| |/
| o 41b3f17 3m xxxxx x xxx x
| |
| @ 2925d3d 2m (redacted-ref-1) x
|
o 9148ff0 10m x
& (merge) 41b3f17 3m xxxxx x xxx x
Event ID: 55, transaction ID: 33 (message: reference-transaction)
RefUpdateEvent { timestamp: 1682006640.556821, event_tx_id: EventTransactionId(33), ref_name: ReferenceName("HEAD"), old_oid: 41b3f171ded1aba53df6507f205a6e1e637adccf, new_oid: 2925d3dda0ea95e6ba1da7def817ddf1f2c583d3, message: None }
RefUpdateEvent { timestamp: 1682006640.556821, event_tx_id: EventTransactionId(33), ref_name: ReferenceName("refs/heads/redacted-ref-1"), old_oid: 41b3f171ded1aba53df6507f205a6e1e637adccf, new_oid: 2925d3dda0ea95e6ba1da7def817ddf1f2c583d3, message: None }
O 2b9e5e4 10m x
|\
| x 946add0 10m (rewritten as 03f978e2) x
| |\
| | x 6a5adf7 10m (rewritten as 19109bef) x
| | |
| | | & (merge) d1bd0cd 10m (rewritten as 9148ff00) x
| | |/
| | o ddb693a 10m xxxxx x xxx x
| | |
| | o 7998214 10m x
| |
| x d1bd0cd 10m (rewritten as 9148ff00) x
| & (merge) ddb693a 10m xxxxx x xxx x
|
O 7333fea 10m (main) x
|
o 03f978e 10m (redacted-ref-0) x
|\
| o 19109be 10m x
| |
| | & (merge) 9148ff0 10m x
| |/
| o 41b3f17 3m xxxxx x xxx x
| |
| @ 2925d3d 2m (redacted-ref-1) x
|
o 9148ff0 10m x
& (merge) 41b3f17 3m xxxxx x xxx x
Event ID: 54, transaction ID: 31 (message: post-merge)
CommitEvent { timestamp: 1682006628.0, event_tx_id: EventTransactionId(31), commit_oid: NonZeroOid(41b3f171ded1aba53df6507f205a6e1e637adccf) }
O 2b9e5e4 10m x
|\
| x 946add0 10m (rewritten as 03f978e2) x
| |\
| | x 6a5adf7 10m (rewritten as 19109bef) x
| | |
| | | & (merge) d1bd0cd 10m (rewritten as 9148ff00) x
| | |/
| | o ddb693a 10m xxxxx x xxx x
| | |
| | o 7998214 10m x
| |
| x d1bd0cd 10m (rewritten as 9148ff00) x
| & (merge) ddb693a 10m xxxxx x xxx x
|
O 7333fea 10m (main) x
|
o 03f978e 10m (redacted-ref-0) x
|\
| o 19109be 10m x
| |
| | & (merge) 9148ff0 10m x
| |/
| o 41b3f17 3m xxxxx x xxx x
| |
| @ 2925d3d 2m (redacted-ref-1) x
|
o 9148ff0 10m x
& (merge) 41b3f17 3m xxxxx x xxx x
Event ID: 52, transaction ID: 30 (message: reference-transaction)
RefUpdateEvent { timestamp: 1682006628.431692, event_tx_id: EventTransactionId(30), ref_name: ReferenceName("HEAD"), old_oid: 19109befd284daa2d2656da6ad06195a402a25c9, new_oid: 41b3f171ded1aba53df6507f205a6e1e637adccf, message: None }
RefUpdateEvent { timestamp: 1682006628.431692, event_tx_id: EventTransactionId(30), ref_name: ReferenceName("refs/heads/redacted-ref-1"), old_oid: 19109befd284daa2d2656da6ad06195a402a25c9, new_oid: 41b3f171ded1aba53df6507f205a6e1e637adccf, message: None }
O 2b9e5e4 10m x
|\
| x 946add0 10m (rewritten as 03f978e2) x
| |\
| | x 6a5adf7 10m (rewritten as 19109bef) x
| | |
| | | & (merge) d1bd0cd 10m (rewritten as 9148ff00) x
| | |/
| | o ddb693a 10m xxxxx x xxx x
| | |
| | o 7998214 10m x
| |
| x d1bd0cd 10m (rewritten as 9148ff00) x
| & (merge) ddb693a 10m xxxxx x xxx x
|
O 7333fea 10m (main) x
|
o 03f978e 10m (redacted-ref-0) x
|\
| o 19109be 10m x
| |
| | & (merge) 9148ff0 10m x
| |/
| o 41b3f17 3m xxxxx x xxx x
| |
| @ 2925d3d 2m (redacted-ref-1) x
|
o 9148ff0 10m x
& (merge) 41b3f17 3m xxxxx x xxx x
Event ID: 50, transaction ID: 28 (message: reference-transaction)
RefUpdateEvent { timestamp: 1682006611.840467, event_tx_id: EventTransactionId(28), ref_name: ReferenceName("HEAD"), old_oid: 7998214f05f05d1ca9c82d74e28bdd05d183234e, new_oid: 19109befd284daa2d2656da6ad06195a402a25c9, message: None }
RefUpdateEvent { timestamp: 1682006611.840467, event_tx_id: EventTransactionId(28), ref_name: ReferenceName("refs/heads/redacted-ref-1"), old_oid: 7998214f05f05d1ca9c82d74e28bdd05d183234e, new_oid: 19109befd284daa2d2656da6ad06195a402a25c9, message: None }
O 2b9e5e4 10m x
|\
| x 946add0 10m (rewritten as 03f978e2) x
| |\
| | x 6a5adf7 10m (rewritten as 19109bef) x
| | |
| | | & (merge) d1bd0cd 10m (rewritten as 9148ff00) x
| | |/
| | o ddb693a 10m xxxxx x xxx x
| | |
| | o 7998214 10m x
| |
| x d1bd0cd 10m (rewritten as 9148ff00) x
| & (merge) ddb693a 10m xxxxx x xxx x
|
O 7333fea 10m (main) x
|
o 03f978e 10m (redacted-ref-0) x
|\
| o 19109be 10m x
| |
| | & (merge) 9148ff0 10m x
| |/
| o 41b3f17 3m xxxxx x xxx x
| |
| @ 2925d3d 2m (redacted-ref-1) x
|
o 9148ff0 10m x
& (merge) 41b3f17 3m xxxxx x xxx x
Version of git-branchless
No response
Version of git
No response
Thanks for reporting. I would also recommend that you check out Jujutsu if you want to rebase merge commits often, as it's more likely to be correct and generally supports the workflow better.