V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
MiketsuSmasher
V2EX  ›  问与答

Git 如何根据不同远程仓库推送不同内容的 README

  •  
  •   MiketsuSmasher · 2022-02-26 11:50:57 +08:00 via Android · 1431 次点击
    这是一个创建于 792 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我有个仓库,需要推送到 Github 和 Notabug 上。现在想要根据不同托管平台上的远程仓库,推送不同内容(主要是各种超链接不同)的 README ,有什么方法可以做到吗?

    8 条回复    2022-02-26 16:10:42 +08:00
    zacharyjia
        1
    zacharyjia  
       2022-02-26 12:01:59 +08:00
    做两个分支,然后在不同平台上设置不同的默认分支?
    foam
        2
    foam  
       2022-02-26 12:27:00 +08:00 via Android
    readme 不要放本地 git 就行了。在远程仓库管理
    foam
        3
    foam  
       2022-02-26 12:40:04 +08:00 via Android
    sorry ,忽略了 git pull 会有问题。那方案就复杂点了:
    1 ,弄个不在 git 管理的目录,放多个 readme
    2 ,分支: master ,分支 g ,分支 n
    3 ,推送时,分支 g n rebase master 分支,并分别 cp 对应的 readme ,push 到对应的远程即可

    以上这些命令自动化就行,弄个别名,简单方便。

    P.S. 为啥要区分 readme ?
    MiketsuSmasher
        4
    MiketsuSmasher  
    OP
       2022-02-26 12:52:40 +08:00
    @foam 详细的使用说明和许可证等信息不在 README.md 里面,在同一仓库的其他文件里,所以要根据托管平台修改对应文件的链接
    0o0O0o0O0o
        5
    0o0O0o0O0o  
       2022-02-26 12:58:39 +08:00
    如果主要使用 Github ,那 git hooks 里对别的平台 sed + commit + force push + reset 不知道行不行
    wzzzx
        6
    wzzzx  
       2022-02-26 13:15:27 +08:00
    1 楼的方法应该是正解,只能维护俩分支了
    windyskr
        7
    windyskr  
       2022-02-26 16:05:28 +08:00 via iPhone   ❤️ 2
    用相对路径试试?

    A relative link is a link that is relative to the current file. For example, if you have a README file in root of your repository, and you have another file in docs/CONTRIBUTING.md, the relative link to CONTRIBUTING.md in your README might look like this:

    [Contribution guidelines for this project](docs/CONTRIBUTING.md)

    GitHub will automatically transform your relative link or image path based on whatever branch you're currently on, so that the link or path always works. You can use all relative link operands, such as ./ and ../.

    https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes
    Senorsen
        8
    Senorsen  
       2022-02-26 16:10:42 +08:00
    ls 方案+1.

    又是个 XY Problem
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2595 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.