如何将单个文件的提交提取到新鲜的git树中?

发布于 2025-02-06 19:39:05 字数 427 浏览 0 评论 0 原文

我正在从现有的源树中拆分库,以便可以单独维护库。

您如何提取一个文件的所有提交并将其导入另一棵树,但没有所有的.git/对象从原始树中杂乱无章?

我当时在想这样的事情:

cd /new/tree
git init

cd /original/tree
git show --reverse  815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
    (cd /new/tree ; git am)

但是它会出现错误并且不会导入。

我还想到了仅分支,删除所有内容,然后将修剪的分支取得到新树中---但(我认为)会导入所有其他树的提交数据中的所有。 。

是否有一种“正确的”方式干净地做到这一点?

I'm splitting out a library from an existing source tree so the library can be maintained separately.

How do you extract all the commits for one file and import them into another tree, but without all the .git/objects clutter from the original tree?

I was thinking something like this:

cd /new/tree
git init

cd /original/tree
git show --reverse  815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
    (cd /new/tree ; git am)

but it gives errors and won't import.

I also thought of just branching, deleting everything, and then fetching the pruned branch into a new tree---but (I think) that would import all the other tree's commit data in .git/objects that would be orphaned in the new tree.

Is there a "proper" way to do this cleanly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔戏命师 2025-02-13 19:39:05

复制从 https://github.com/ pdlporters/devops/blob/master/notes.md#how-to-split-History

如何拆分历史记录

确保已安装 git-subtree 已安装并有效(如果不是,请从
和place
+X /usr/usr/local/libexec/git-core/git-subtree

# example for pdla-io-hdf
KITCHENSINKREPO=$HOME/pdla
KITCHENSINKDIR=IO/HDF
SPLITOUTREPO=$HOME/pdla-io-hdf
SPLITBRANCH=splitout
MASTER=master
pushd $KITCHENSINKREPO
git subtree split -P $KITCHENSINKDIR -b $SPLITBRANCH
git push $SPLITOUTREPO $SPLITBRANCH:$SPLITBRANCH
git branch -D $SPLITBRANCH
cd $SPLITOUTREPO
git checkout $MASTER
git reset --hard $SPLITBRANCH
git branch -d $SPLITBRANCH
git push origin
popd

Copied from https://github.com/PDLPorters/devops/blob/master/NOTES.md#how-to-split-history:

How to split history

Make sure git-subtree is installed and works (if not, get from
https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh and place
with +x in /usr/local/libexec/git-core/git-subtree)

# example for pdla-io-hdf
KITCHENSINKREPO=$HOME/pdla
KITCHENSINKDIR=IO/HDF
SPLITOUTREPO=$HOME/pdla-io-hdf
SPLITBRANCH=splitout
MASTER=master
pushd $KITCHENSINKREPO
git subtree split -P $KITCHENSINKDIR -b $SPLITBRANCH
git push $SPLITOUTREPO $SPLITBRANCH:$SPLITBRANCH
git branch -D $SPLITBRANCH
cd $SPLITOUTREPO
git checkout $MASTER
git reset --hard $SPLITBRANCH
git branch -d $SPLITBRANCH
git push origin
popd
绮烟 2025-02-13 19:39:05

这起作用了。如果您有更好的方法,我也愿意接受其他答案:

git format-patch --stdout 815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
    (cd ../perl-PDL-Opt-Simplex-Simple/ ; git am)

This worked. I'm open to other answers, too, if you have a better way:

git format-patch --stdout 815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
    (cd ../perl-PDL-Opt-Simplex-Simple/ ; git am)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文