使用一个命令添加并提交对 git 的所有分支的更改

Add and commit changes to all git's branches with one command

我的计算机中有一个 git 存储库,此存储库中的目录之一是一个 git 工作树,其中包含文档的 html 版本。所以树是这样的

. # <--- main branches here!
├── docs
│   └── _build
│       ├── doctrees
│       ├── html # <--- gh-pages branch here!
│       │   ├── _modules
│       │   ├── _sources
│       │   └── _static
│       └── latex
├── examples
└── mypackage
    ├── subpackages
    └── subpackages

当我在文档上工作时,两个分支(devgh-pages)都会更新,因为我更改了 docs 目录中的文件,然后 sphinx 编译 html 进入 html 目录。

然而,当我完成这个过程后,我必须在主分支和 gh-pages 分支中手动执行 git add . && git commit,然后将所有更改推送到 git.

这不是很麻烦,但如果我可以对所有分支发出一条命令,那会很方便。我知道 git push 可以是 "defaulted" 来推送所有分支(这就是我所做的)但是我发现没有办法这样做来添加和提交诸如(例如;只是为了或澄清)

git add . --allbranches
git commit --allbranches -m "updated the docs"
git push

或类似的东西。有办法吗?

干杯!

无法一次提交多个分支,也无法合并当前未签出的分支。

但是你可以稍微缩短命令。要添加所有更改并进行提交,然后推送一行

git commit -am "commit message" && git push

我的项目通常有一个包含 "development" 内容的顶级目录。所以我可能会制作一个脚本 scripts/build_doc.sh(或您喜欢的任何语言),如下所示:

#!/bin/bash

if [ "`git status -z`" != "" ] ; then echo Need clean directory ; exit 1 ; fi

whatever_command_to_rebuild_pages

git add -A dir_to_built_html_pages && \
git commit -m "autobuild" && \
git push 

两个想法:1) 您可以在提交挂钩中执行此操作,2) 您确定要在存储库中生成文件吗?