V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MiketsuSmasher
V2EX  ›  问与答

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

  •  
  •   MiketsuSmasher · Feb 26, 2022 via Android · 1899 views
    This topic created in 1522 days ago, the information mentioned may be changed or developed.

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

    8 replies    2022-02-26 16:10:42 +08:00
    unifier
        1
    unifier  
       Feb 26, 2022
    做两个分支,然后在不同平台上设置不同的默认分支?
    foam
        2
    foam  
       Feb 26, 2022 via Android
    readme 不要放本地 git 就行了。在远程仓库管理
    foam
        3
    foam  
       Feb 26, 2022 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
       Feb 26, 2022
    @foam 详细的使用说明和许可证等信息不在 README.md 里面,在同一仓库的其他文件里,所以要根据托管平台修改对应文件的链接
    0o0O0o0O0o
        5
    0o0O0o0O0o  
       Feb 26, 2022
    如果主要使用 Github ,那 git hooks 里对别的平台 sed + commit + force push + reset 不知道行不行
    wzzzx
        6
    wzzzx  
       Feb 26, 2022
    1 楼的方法应该是正解,只能维护俩分支了
    windyskr
        7
    windyskr  
       Feb 26, 2022 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  
       Feb 26, 2022
    ls 方案+1.

    又是个 XY Problem
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3757 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 10:36 · PVG 18:36 · LAX 03:36 · JFK 06:36
    ♥ Do have faith in what you're doing.