如何在不使用子模块的情况下在我的存储库中添加/升级​​/降级远程Git项目? [英] How do I add/upgrade/downgrade a remote Git project in my repository without using submodules?

查看:120
本文介绍了如何在不使用子模块的情况下在我的存储库中添加/升级​​/降级远程Git项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想用Git从GitHub下载WordPress更新,然后推出那些通过 git push 和/或 git svn dcommit



<我现在有一个使用Git子模块的解决方案,它可以工作;但现在我需要将我的最新项目部署到仅支持SVN的服务器上,并且我无法直接访问它。因此,子模块已经出来了。



我在 Git的子树合并策略,我认为这是正确的解决方案;但是我读过的所有东西都希望遵循一个远程分支,并总是拉下最近的代码。



相反, GitHub上的WordPress使用它的 master 分支 - 事实上,它的所有分支机构 - 用于发展;版本被标记,但就是这样。正式来说,所有分支都处于永久的alpha状态。



我想我需要弄清楚如何子树合并标签

现在,我正在将WordPress 3.5读入 webroot / wordpress ),它的工作原理:

  $ git remote add -t master --no-tags wordpress git://github.com /WordPress/WordPress.git 
$ git config --add remote.wordpress.fetch + refs / tags / *:refs / tags / wordpress / *
$ git fetch wordpress
warning:no常见提交
remote:计数对象:138547,完成。
remote:压缩对象:100%(28297/28297),完成。
remote:共计138547(delta 110613),重用137367(delta 109624)
接收对象:100%(138547/138547),46.05 MiB | 2.26 MiB / s,完成。
解决三角洲问题:完成100%(110613/110613)。
从git://github.com/WordPress/WordPress
* [new branch] master - > wordpress / master
* [新标签] 1.5 - > wordpress / 1.5
...
* [新标签] 3.5 - > wordpress / 3.5
* [新标签] 3.5.1 - > wordpress / 3.5.1
$ git read-tree --prefix = webroot / wordpress / -u wordpress / 3.5
$ git commit -m在webroot / wordpress中添加WordPress 3.5
[ master c483104]在webroot / wordpress上添加了WordPress 3.5
1061文件已更改,269102插入(+)
创建模式100644 webroot / wordpress / index.php
创建模式100644 webroot / wordpress / license。 txt
创建模式100644 webroot / wordpress / readme.html
...

无论我尝试什么,我都无法弄清楚如何使用子树合并来更新WordPress 3.5.1。



尝试 merge read-tree ,根据这个,无效: code> $ git merge -s我们的--squash --no-commit wordpress / 3.5.1
壁球提交 - 不更新HEAD
自动合并进行得很顺利;在提交请求前停止
$ git read-tree --prefix = webroot / wordpress / -u wordpress / 3.5.1
错误:条目'webroot / wordpress / index.php'与'webroot /的wordpress / index.php的。无法绑定。

尝试子树合并失败:

  $ git merge -s subtree --squash --no-commit wordpress / 3.5.1 
警告:无法合并二进制文件:webroot / wordpress / wp-includes / js / tinymce /wp-tinymce.js.gz(HEAD vs. wordpress / 3.5.1)
...
壁球提交 - 不更新HEAD
自动合并失败;修复冲突,然后提交结果。

git pull -s子树--squash --no-commit wordpress )



我尝试添加 -Xtheirs > to git merge ,我试着用 -Xsubtree 递归 merge c $ c>,我已经尝试了各种临时分支和子树合并的组合,但我无法破解它。



任何想法?或者我应该放弃并下载(并重新下载和重新下载)WordPress的老式方式? 解决方案

如果你想要做的只是将一个远程文件拖到你的项目中,并且你不关心把它的历史连接到你的项目,那么不需要合并。



<最终,解决方案很简单:


  • 从Git索引中删除旧版本的WordPress;

  • 使用读取树;

  • 提交,将新版本的WordPress引入Git索引。



  • $ p code $ read-tree
    是您在这里唯一需要的工具,并且自阅读树(巧妙地)拒绝覆盖文件,你只需要从索引中删除旧的树,然后再阅读新的树。

      $ git rm -r webroot / wordpress 
    rm'webroot / wordpress / index.php'
    rm'webroot / wordpress / license.txt'
    rm 'webroot / wordpress / readme.html'
    ...
    $ git read-tree --prefix = webroot / wordpress / -u wordpress / 3.5.1
    $ git commit -m更新到WordPress 3.5.1
    [master 9665ad7]已更新至WordPress 3.5.1
    更改了44个文件,406个插入(+),176个删除( - )
    重写了webroot / wordpress / wp (99%)
    重写webroot / wordpress / wp-includes -includes / js / media-views.min.js(89%)
    ...


    I need to keep a copy of WordPress in my project's Git repository.

    I want to use Git to pull down WordPress updates from GitHub, and then push out those updates via git push and/or git svn dcommit.

    I currently have a solution in place using Git submodules, and it works; but now I need to deploy my newest project to a server that only supports SVN, and to which I have no direct access whatsoever. Therefore, submodules are out.

    I've done a ton of reading on Git's subtree merging strategy, and I think it's the right solution; but everything I've read expects that I'd want to follow a remote branch, and always pull down its most recent code.

    On the contrary, WordPress on GitHub uses its master branch – in fact, all of its branches – for development; releases are tagged, but that's it. Officially speaking, all branches are in a perpetual alpha state.

    I think what I need to figure out is how to subtree merge a tag.

    Right now, I'm doing this to read WordPress 3.5 into webroot/wordpress (and to namespace WordPress tags), and it works:

    $ git remote add -t master --no-tags wordpress git://github.com/WordPress/WordPress.git
    $ git config --add remote.wordpress.fetch +refs/tags/*:refs/tags/wordpress/*
    $ git fetch wordpress
    warning: no common commits
    remote: Counting objects: 138547, done.
    remote: Compressing objects: 100% (28297/28297), done.
    remote: Total 138547 (delta 110613), reused 137367 (delta 109624)
    Receiving objects: 100% (138547/138547), 46.05 MiB | 2.26 MiB/s, done.
    Resolving deltas: 100% (110613/110613), done.
    From git://github.com/WordPress/WordPress
     * [new branch]      master     -> wordpress/master
     * [new tag]         1.5        -> wordpress/1.5
    ...
     * [new tag]         3.5        -> wordpress/3.5
     * [new tag]         3.5.1      -> wordpress/3.5.1
    $ git read-tree --prefix=webroot/wordpress/ -u wordpress/3.5
    $ git commit -m "Added WordPress 3.5 at webroot/wordpress"
    [master c483104] Added WordPress 3.5 at webroot/wordpress
     1061 files changed, 269102 insertions(+)
     create mode 100644 webroot/wordpress/index.php
     create mode 100644 webroot/wordpress/license.txt
     create mode 100644 webroot/wordpress/readme.html
    ...
    

    No matter what I try, though, I can't figure out how to use subtree merging to update this with WordPress 3.5.1.

    Trying merge and read-tree, as per this, doesn't work:

    $ git merge -s ours --squash --no-commit wordpress/3.5.1
    Squash commit -- not updating HEAD
    Automatic merge went well; stopped before committing as requested
    $ git read-tree --prefix=webroot/wordpress/ -u wordpress/3.5.1
    error: Entry 'webroot/wordpress/index.php' overlaps with 'webroot/wordpress/index.php'.  Cannot bind.
    

    Trying a subtree merge fails:

    $ git merge -s subtree --squash --no-commit wordpress/3.5.1
    warning: Cannot merge binary files: webroot/wordpress/wp-includes/js/tinymce/wp-tinymce.js.gz (HEAD vs. wordpress/3.5.1)
    ...
    Squash commit -- not updating HEAD
    Automatic merge failed; fix conflicts and then commit the result.
    

    (git pull -s subtree --squash --no-commit wordpress 3.5.1 fails the same way.)

    I've tried adding -Xtheirs to git merge, I've tried a recursive merge with -Xsubtree, I've tried every combination of temporary branches and subtree merging that I can figure out – but I can't seem to crack this.

    Any ideas? Or should I just give up and download (and re-download, and re-download) WordPress the old-fashioned way?

    解决方案

    If all you want to do is frequently pull a remote's files into your project, and you don't care about connecting its history to yours, then no merging is required whatsoever.

    Ultimately, the solution is dead simple:

    • Remove the old version of WordPress from the Git index;
    • Pull the new version of WordPress into the Git index with read-tree;
    • Commit.

    read-tree is the only tool you need here, and since read-tree (smartly) refuses to overwrite files, you just need to remove the old tree from the index before reading the new one into its place.

    $ git rm -r webroot/wordpress
    rm 'webroot/wordpress/index.php'
    rm 'webroot/wordpress/license.txt'
    rm 'webroot/wordpress/readme.html'
    ...
    $ git read-tree --prefix=webroot/wordpress/ -u wordpress/3.5.1
    $ git commit -m "Updated to WordPress 3.5.1"
    [master 9665ad7] Updated to WordPress 3.5.1
     44 files changed, 406 insertions(+), 176 deletions(-)
     rewrite webroot/wordpress/wp-admin/js/post.min.js (81%)
     rewrite webroot/wordpress/wp-includes/js/media-editor.min.js (99%)
     rewrite webroot/wordpress/wp-includes/js/media-views.min.js (89%)
    ...
    

    这篇关于如何在不使用子模块的情况下在我的存储库中添加/升级​​/降级远程Git项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆