如何跨Git仓库中的所有分支更新文件 [英] How to update a file across all branches in a Git repository
问题描述
在存储库中有多个分支的情况下:如何简单地更新所有分支中的文件。
在这种情况下,它是一个类似于bashrc的文件,它指定了一些环境变量。我在过去更新了主分支版本,然后重新分配了每个分支。这有一个n + 1的开销,我想避免。
扩展 fork0 的
a href =https://stackoverflow.com/a/3847586/6309>如何使用bash脚本遍历所有git分支
git checkout
从另一个特定文件分支( git checkout< branch_name> - <路径>
,来自 git checkout
手册页) :
#!/ bin / bash
branches =()
eval$(git for-each-ref --shell --format ='branches + =(%(refname))'refs / heads /)
用于$ {branches [@]}中的分支。如果[[$ {branch}!=master]]执行
;然后
git checkout $ {branch}
git checkout master - yourFile
fi
done
(这适用于您的情况,因为此处始终检查 master
分支中的文件。)
In the case that a a repository has a number of branches: How does one simply update a file across all the branches.
In this case it's a bashrc like file that specifies some environments variables. I have in the past updated the master branch version then rebased each branch. This has a sort of n+1 overhead, I'd like to avoid.
To extend fork0's comment, you need to combine:
- "How to iterate through all git branches using bash script"
- "
git checkout
specific files from another branch" (git checkout <branch_name> -- <paths>
, fromgit checkout
man page)
Ie:
#!/bin/bash
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
for branch in "${branches[@]}"; do
if [[ "${branch}" != "master" ]]; then
git checkout ${branch}
git checkout master -- yourFile
fi
done
(This is be adapted to your case, since here it always checkout the file from the master
branch.)
这篇关于如何跨Git仓库中的所有分支更新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!