【问题标题】:How can I reset hard all branches in git如何在 git 中硬重置所有分支
【发布时间】:2016-09-20 14:16:49
【问题描述】:

如何重置我的所有本地分支,一次就像远程存储库中的分支一样?

我的本​​地存储库中有 42 个分支,但我的远程存储库中只有 21 个分支。我不需要其他分支,我只需要 21 个分支(本地和远程同名)。

我知道

git fetch origin 
git reset --hard origin/master

但我希望所有 21 个分支一起硬重置为原始状态,并删除所有其他不在原始状态的分支。

【问题讨论】:

  • 只需删除存储库并从源克隆一个新的。

标签: git git-reset


【解决方案1】:

如果你在 Unix 上,你可以使用 shell 脚本。

这将首先删除所有您的本地分支,然后从原点创建所有分支。

# make sure we are currently on no branch, so every branch can be deleted
git checkout --detach master

# delete all local branches
git branch | grep -v "HEAD detached" | xargs git branch -D

# re-create all branches from origin
while read b; do git branch ${b#origin/} $b; done < <(git branch -r | grep 'origin/')

# check out the new master
git checkout master

【讨论】:

    猜你喜欢
    • 2020-10-14
    • 2015-12-20
    • 2021-06-11
    • 2010-09-09
    • 2015-04-26
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多