修改git

时间:2017-09-21 20:27:47

标签: git github git-submodules

我正在使用最新版本的ardupilot固件。 目标是让ardupilot使用mavlink协议与配套板进行交谈。

我开始在我的github帐户上创建原始ardupilot存储库的分支。

配套板的集成需要我修改ardupilot存储库的一些子模块的代码:PX4Firmware和mavlink。

因此,为了能够做到这一点,我还在我的github帐户上分叉了ardupilot的各个子模块。

然后,我在ardupilot repo的fork上修改了.gitmodules文件,以确保子模块的初始化使用我的forks而不是原来的。修改如下:

[submodule "modules/PX4Firmware"]
path = modules/PX4Firmware
url = git://github.com/MY_GITHUB_ACCOUNT/PX4Firmware.git
[submodule "modules/PX4NuttX"]
path = modules/PX4NuttX
url = git://github.com/MY_GITHUB_ACCOUNT/PX4NuttX.git
[submodule "modules/uavcan"]
path = modules/uavcan
url = git://github.com/MY_GITHUB_ACCOUNT/uavcan.git
[submodule "modules/waf"]
path = modules/waf
url = git://github.com/MY_GITHUB_ACCOUNT/waf.git
[submodule "modules/gbenchmark"]
path = modules/gbenchmark
url = git://github.com/MY_GITHUB_ACCOUNT/benchmark.git
[submodule "modules/mavlink"]
path = modules/mavlink
url = git://github.com/MY_GITHUB_ACCOUNT/mavlink
[submodule "gtest"]
path = modules/gtest
url = git://github.com/MY_GITHUB_ACCOUNT/googletest

在此之后,我意识到我还需要修改PX4Firmware的一个子模块的代码。因此,我在PX4Firmware仓库中重复了相同的步骤:

  1. 我的github帐户上的子子模块的分支
  2. 修改PX4Firmware仓库内的.gitmodules文件,如下所示:

    [submodule "mavlink/include/mavlink/v1.0"]
    path = mavlink/include/mavlink/v1.0
    url = git://github.com/MY_GITHUB_ACCOUNT/c_library.git
    [submodule "src/modules/uavcan/libuavcan"]
    path = src/modules/uavcan/libuavcan
    url = git://github.com/UAVCAN/libuavcan.git
    [submodule "Tools/genmsg"]
    path = Tools/genmsg
    url = https://github.com/ros/genmsg.git
    [submodule "Tools/gencpp"]
    path = Tools/gencpp
    url = https://github.com/ros/gencpp.git
    [submodule "src/lib/matrix"]
    path = src/lib/matrix
    url = https://github.com/PX4/Matrix.git
    [submodule "src/lib/DriverFramework"]
    path = src/lib/DriverFramework
    url = https://github.com/PX4/DriverFramework.git
    [submodule "src/lib/ecl"]
    path = src/lib/ecl
    url = https://github.com/PX4/ecl.git
    
  3. 修改文件后,我运行命令 git submodule sync git submodule update 。我还提交了两个.gitmodules文件并将它们推送到相应的主分支。

    为了查看它是否有效,我将ardupilot的分支克隆到一个新文件夹中,并递归地初始化所有子模块:

    git clone https://github.com/MY_GITHUB_ACCOUNT/ardupilot.git
    cd ardupilot
    git submodule update --init --recursive
    

    不幸的是,它并没有按预期工作。虽然我的ardupilot分支的子模块似乎是从我的github下载的,但PX4Firmware的子模块仍然是从原始的回购中下载的。

    在这里你可以找到 git子模块更新--init --recursive 命令的输出:https://pastebin.com/ECi4wQEZ

    我的问题是我无法承诺原始存储库,当然,据我所知,因此我必须使用forks来跟踪我的修改。

    我已经在stackoverflow上找到并尝试了许多asnwers:

    1. How do I replace a git submodule with another repo?
    2. Changing remote repository for a git submodule
    3. 以及其他许多人,但在我的案例中都没有。

      你有什么建议吗?

      谢谢。

      --------更新--------

      与此同时,我找到了一种方法让它发挥作用。

      我在这里描述了程序,以防有人需要它或知道更好的方法:

      我开始解决子子模块的url问题:确保PX4Firmware repo使用git://github.com/MY_GITHUB_ACCOUNT/c_library.git而不是原始版本。

      以下是程序:

      1. 转到我的github上的PX4Firmware仓库的主页
      2. 修改.gitmodules文件(更改网址)。 注意:我已经发现git协议不允许推送,因此我使用了https。
      3. 保存更改。
      4. 在我的电脑上克隆PX4Firmware存储库。
      5. 使用命令 git submodule update --init --recursive
      6. 进入PX4Firmware仓库的根文件夹后初始化子模块
      7. cd进入子模块文件夹
      8. 运行命令 git checkout __sha __ ,其中 sha 是我的子子模块本地副本的最新提交。
      9. 使用 cd ..
      10. 上升一级
      11. 运行命令 git add submodule_folder
      12. git commit然后按
      13. 从主存储库(ardupilot)我重复了相同的过程,以确保PX4Firmware子模块是我的存储库上的fork而不是原始的。

        我确定有更好的方法可以做到这一点。如果您知道,请分享。 我也希望这可以帮助其他人解决同样的问题。

0 个答案:

没有答案