仅备份git存储库中的“本地”提交/对象

时间:2014-01-01 19:47:40

标签: git backup

我想在我的本地存储库中备份(通过dropbox或google驱动器或类似方式)未提交的提交。备份整个存储库(使用git push --mirror或类似)是多余的,因为99%的提交存在于中央共享存储库中,以及我们团队中所有其他开发人员的计算机上。此外,repo的完整克隆可能会超出我的目标备份系统中的配额。

我认为我想要的是某种git bundle命令,但我不确定如何将等效的--all not in any remote refs传递给它。

2 个答案:

答案 0 :(得分:2)

This answer列出了使用^<remote>/<branch>排除从远程分支可到达的所有提交的基本原则。

这个脚本可以帮到你:

# See https://stackoverflow.com/a/18359250/3150057 for awk branch parsing.
# Get all local branch names.
LOCAL_HEADS=$(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}')
# Get all remote branch names, prefixed with ^ to 'not' them.
REMOTE_HEADS=$(git branch -r | awk -F ' +' '! /\(no branch\)/ {print "^"$2}')

# -- is needed at the end to tell git we are only giving it revisions.
# List all commits reachable from local branches and tags but exclude those reachable by the remote branches.
git rev-list $REMOTE_HEADS $LOCAL_HEADS --tags --
# Pass the same args to create a bundle of all the above commits.
git bundle create my-backup-today.bundle $REMOTE_HEADS $LOCAL_HEADS --tags --

答案 1 :(得分:0)

除非您的存储库很大,否则我不确定是否会看到绕过git push的好处。

首次完成后,push es成为增量版,从私有遥控器中取回数据非常容易。您的新private-remote/*远程分支会在视觉上向您显示push已编辑的内容以及未编辑的内容。

使用git bundle,您的工作流程变得更加复杂,并且您无法查看已备份哪些提交。

相关问题