问题描述
首先这是不同的,因为这是针对所有分支而不是一个。 (我发现的所有对象一次都只指定一个分支)
First this is different because this is for all branches not one. (All the ones I have found only specify this for a single branch at a time)
我在一个大约有20-30个分支的仓库中工作(长话短说,我知道我知道)
I work on a repo that has about 20-30 branches (long story bad practice I know I know)
无论如何,我正在使用git bfg清理程序删除一些旧的提交,使用它之后,您需要删除并重新编写代码或重置每个分支。
anyways I was deleting some old commits using the git bfg cleaner and after using it you need to either delete and reclone the code or reset every branch.
我知道如何使用
git fetch origin
git reset --hard origin/master
但是有一种方法可以用一个命令还是一次必须做一个分支?
But is there a way to reset every branch with one command or do I have to do it one branch at a time?
我有很多本地文件被忽略,我不想处理复制和重写。 (例如IDE文件,计算机配置文件等)。
I have a lot of local files ignored that I do not want to deal with copying and rewriting. (like IDE files, computer config files, etc...)
推荐答案
您可以使用一个脚本,该脚本将遍历您的分支,然后对每个分支执行您想做的事情:
You can use a script which which will loop over your branches and then do what ever you want on each one:
# Loop on all the desired branches
for ref in $(git branch -a)
do
# ... DO ANYTHING YOU NEED HERE
# You have the $ref which stores the branch name
# ex: remotes/origin/master
done
有没有更好的简单解决方案?
是的,只需再次克隆该项目,您的内容就会与您的来源相同。
这正是您在每个分支上手动执行的操作。
Is there a better ans simple solution?
Yes, simply clone the project again and you will have the same content as your origin.
This is exactly what you do manually per branch.
注意:
您可以使用此命令一次获取所有数据:
You can fetch all the data at once using this command:
# Fetch all remotes, branches and remove deledted content
git fetch --all --prune
这篇关于将本地存储库的所有分支重置为与远程相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!