【问题标题】:Git: backup (or archive) stale remote branchesGit:备份(或存档)过时的远程分支
【发布时间】:2015-08-25 00:55:07
【问题描述】:

有没有办法在我们的遥控器上备份、存档或以某种方式存储一些陈旧的分支?我们以某种方式在一个项目中积累了一个完整的页面,随着时间的推移,人们来来去去,他们的分支大多只是挡道。我想删除和修剪它们,但如果我能以某种方式备份它们。

想法?

【问题讨论】:

  • 把它们变成标签,这样就不会出现在你的git branch 输出中?参考就是参考,如果您实际上并没有在这些分支上开发,那么标记就可以了。

标签: git archive


【解决方案1】:

我为此目的创建并运行了这个自动化脚本,因为我不想只是将它们转换成陈旧的标签。

脚本为每个分支差异生成补丁文件。您可以将它们存档在您喜欢的位置。

# Fetch the remote repos
git fetch

# List no-merged remote branches
BRANCHES=`git branch -r --no-merged | awk '{print($1)}'`

# List time-sorted branches with their time, id and author
for BRANCH in $BRANCHES; 
    do echo -e `git show --format="%ci %h %an" $BRANCH | head -n 1` \\t$BRANCH;
    done | sort -r > targets

# Manually select the target lines
vim targets

# List branch names from it
BRANCHES=`cut -f 2 < targets`

# Dump the diffs of the branches
for BRANCH in $BRANCHES;
    do git diff --no-prefix -U10 HEAD...$BRANCH > ${BRANCH//\//+}.patch;
    done

# Delete the branches on the remote repo
REMOTE=origin
for BRANCH in $BRANCHES;
    do BRANCH_IN_REMOTE=$(echo $BRANCH | sed "s/$REMOTE\///g");
       echo "Deleting $BRANCH_IN_REMOTE";
       git push $REMOTE --delete $BRANCH_IN_REMOTE;
    done

【讨论】:

    猜你喜欢
    • 2020-11-20
    • 2012-10-22
    • 2014-06-20
    • 2021-03-12
    • 2021-03-07
    • 1970-01-01
    • 2013-02-21
    • 2013-07-22
    • 2016-06-26
    相关资源
    最近更新 更多