简体   繁体   中英

How do I rebase a subtree?

I am experimenting with Git subtree and I need some help.

I have a repo A , with a subtree, generated from an upstream repo B , in folder A/b . There is a file in the upstream B/x , and I can see that the equivalent file A/b/x exists and is up to date. If I first modify the upstream file A/b/x , and the downstream file B/x , when I call git subtree push ... I get a merge conflict, as expected.

I can do a git subtree pull ... which performs a merge which is applied over my B/x edit. I would prefer to do a rebase operation where my change to B/x is applied over the A/b/x edit.

How can I do this?

Git subtree doesn't seem to support rebase (as one of two methods of "integrating" changes: rebase or merge). There is one TODO mentioning rebase, but I think it's in a different context.

The subtree pull command doesn't even issue a git pull command, but splits it into the two necessary commands, fetch + merge, or I would suggest overriding pull's default integration strategy ( pull.rebase ).

https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L870

If I understand your scenario correctly, I think you should avoid modifying B/x directly in its repository. Subtree allows you to modify A/b/x and to use subtree push to send the changes to the subtree's remote.

Either way, subtree isn't really "rebase" aware. You could always rebase the B remote directly, but you would still need to merge unrelated histories in A . That gets tricky and, for me, seems to require interactive rebase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM