gpt4 book ai didi

git - 如何使推送/拆分的子树保持最新状态?

转载 作者:太空狗 更新时间:2023-10-29 14:08:06 24 4
gpt4 key购买 nike

假设您有一个带有子目录“A/mySubDir”的存储库“A”,并且您想将“A/mySubDir”分离到一个新的存储库“B”中

git init B
cd <repo A>
git subtree split --prefix==A/mySubDir --branch=split
git push 'B' split:master

假设 repo “A”上的 HEAD 现在位于 12fe。我更新了“A/mySubDir”中的一些文件。

当“A/mySubDir”中的文件发生变化时,如何使“B”保持最新?

git subtree split --prefix==A/mySubDir --branch=split 12fe..

以错误结尾:分支 'split' 不是提交 'XXXX' 的 anchor

有人知道吗?

问候,格特

最佳答案

您已完成第一步(拆分您的 A 存储库),但您尚未将 B 存储库放回 A,如“Using Git subtrees for repository separation”中所述:

这是一个摘录,适用于您的 A/mySubDir - B 情况:

将存储库添加为主存储库的子树

In your main repository, you need to get rid of the original files that you split, and then add the remote repository as a subtree instead.

Delete the entire directory you split from, and then commit.

git rm -r A/muSubdir
git commit -am "Remove split code."

Add the new shared repository as a remote

git remote add B /url/to/B.git

Now add the remote repository as a subtree

git subtree add --prefix=A/mySubDir --squash shared master

Note: we use the -–squash switch because we probably just want a single snapshot commit representing version X of the shared module, rather than complicating our own commit history with spurious upstream bugfix commits. Of course if you want the entire history then feel free to leave off that switch.

You now have subtree based on an upstream repository. Nice.

http://makingsoftware.files.wordpress.com/2013/02/gitsubtreeadd_thumb.png?w=500&h=196

In the image you can see the bottom commit is the squashed commit containing all the upstream code and this is merged with your code.

Important note: Do not be tempted to rebase this. Push it as is.
If you rebase, git subtree won’t be able to reconcile the commits when you do your next subtree pull.

So far so good. But this isn’t much use if you can’t receive changes from the upstream repository. Luckily that’s easy.

pull 上游变更

To pull changes from the upstream repository, just use the following command:

git subtree pull --prefix=A/mySubDir --squash shared master

(You are squashing all newer upstream commits into a single one that will then be merged into your repository).
Important: as mentioned above, do not rebase these commits.

将更改推送到上游存储库

Contributing changes to the upstream repository is as simple as:

git subtree push --prefix=A/mySubDir --squash shared master

关于git - 如何使推送/拆分的子树保持最新状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19863561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com