本文介绍了如何跨Git仓库中的所有分支更新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在存储库中有多个分支的情况下:如何简单地更新所有分支中的文件。
在这种情况下,它是一个类似于bashrc的文件,它指定了一些环境变量。我在过去更新了主分支版本,然后重新分配了每个分支。这有一个n + 1的开销,我想避免。
在存储库中有多个分支的情况下:如何简单地更新所有分支中的文件。
在这种情况下,它是一个类似于bashrc的文件,它指定了一些环境变量。我在过去更新了主分支版本,然后重新分配了每个分支。这有一个n + 1的开销,我想避免。
扩展的
git checkout< branch_name> - <路径>
,来自) #!/ 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:
git checkout
specific files from another branch" (git checkout <branch_name> -- <paths>
, from git 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仓库中的所有分支更新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!