撤消“git filter-branch ... - --all”?在一个命令? [英] undo "git filter-branch ... -- --all"? in one command?

查看:164
本文介绍了撤消“git filter-branch ... - --all”?在一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始搞乱 git filter-branch 。 --all选项重写所有分支和标签。凉。 git filter-branch 创建它在refs / original中覆盖的所有ref的备份。很酷。现在我想将我所有的实验都放在 filter-branch 之外。



有没有简单的方法来完全取消 git filter-branch<任何过滤器>的影响 - --all ?即将所有重写的分支一次性恢复到原始状态?

如果没有预先存在的方法,应该有。如果没有预先存在的方法,是否有人会有一个简短的脚本来做到这一点?

显然有解决方法。我可以一次手动恢复一个分支,如这个问题。或者我可以干脆重新克隆。或者很快就会在一个有许多分支机构/标签的回购仓库中被分成更小的回购仓库。

这里有一个简单而安全的方法来撤销过滤器分支:

  git fetch。 + refs / original / *:* 

如果当前签出的分支( HEAD )是要恢复的分支之一,此命令将失败。您可以事先运行 git checkout --detach ,让 git fetch 更新所有分支。请记住在运行 git fetch



后检出分支。一旦ref已成功还原,您可以删除 refs / original 使用此命令可以安全地引用:

  git for-each -ref ref / original --format ='delete%(refname)%(objectname)'| git update-ref --stdin 






旧回答:

  git for-each-ref refs / heads refs / tags \ 
- -format ='git update-ref'%(refname)%(refname)@ {1 hour ago}'

为了增加安全性,您可以测试过滤器分支实际上是否更新了ref:

  git for- each-ref refs / heads refs / tags --format ='
{git reflog -1%(refname)| sed -n/ filter-branch:重写$ / Q1; } \
|| git update-ref -m重置为过滤器分支之前\
%(refname)%(refname)@ {1}'| sh -x


I started messing around with git filter-branch. The --all option rewrites all branches and tags. Cool. git filter-branch creates a backup of all refs it overwrites in refs/original. Very Cool. Now I'd like to blow all my experimenting with filter-branch away.

Is there an easy way to completely undo the effects of git filter-branch <whatever filter> -- --all? I.e. to restore all of the rewritten branches to their original state all at once?

If there isn't a preexisting way, there should be. If there isn't a preexisting way, does anybody have a short script that will do it?

Obviously there's workarounds. I could restore it manually, a branch at a time, as in this question. Or I could just nuke and re-clone. Either would get tedious quickly in a repo with many branches/tags that is (say) being split up into smaller repos.

解决方案

Here's a simple and safe way to undo a filter-branch:

git fetch . +refs/original/*:*

If the currently checked out branch (HEAD) is one of the branches to be restored, this command will fail. You can run git checkout --detach beforehand to let git fetch update all branches. Remember to checkout a branch after running git fetch!

Once the refs have been successfully restored, you can delete the refs/original refs safely with this command:

git for-each-ref refs/original --format='delete %(refname) %(objectname)' | git update-ref --stdin


Old answer:

git for-each-ref refs/heads refs/tags \
        --format='git update-ref "%(refname)" "%(refname)@{1 hour ago}"'

For added safety you could test whether the filter-branch actually did update the ref:

git for-each-ref refs/heads refs/tags --format='
        { git reflog -1 "%(refname)" | sed -n "/filter-branch: rewrite$/Q1"; } \
                  || git update-ref -m "reset to before filter-branch" \
                             %(refname) %(refname)@{1}' | sh -x

这篇关于撤消“git filter-branch ... - --all”?在一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆