恐怕我找不到任何类似的场景。
我有一个有很多历史的git存储库:500多个分支,500多个标签,可以追溯到2007年年中。它包含大约19,500个提交。我们希望删除2010年1月1日之前的所有历史记录,使其更小,更容易处理(我们将在存档存储库中保留历史记录的完整副本)。
我知道我想要成为新存储库根的提交。然而,我不能找出正确的git mojo来截断回购以提交开始。我猜是某种变体
git filter-branch
涉及到移植是必要的;可能还需要分别处理我们想要保留的200多个分支中的每个分支,然后将回购补丁重新组合在一起(我确实知道如何做)。
有人做过这样的事吗?我有git 1.7.2.3,如果这很重要的话。
这种方法简单易懂,效果良好。脚本的参数($1)是一个引用(标签,散列,…),指向您想要保存历史记录的提交。
#!/bin/bash
git checkout --orphan temp $1 # create a new branch without parent history
git commit -m "Truncated history" # create a first commit on this branch
git rebase --onto temp $1 master # now rebase the part of master branch that we want to keep onto this branch
git branch -D temp # delete the temp branch
# The following 2 commands are optional - they keep your git repo in good shape.
git prune --progress # delete all the objects w/o references
git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos
注意,旧的标签将仍然存在;因此,您可能需要手动删除它们
备注:我知道这和@yoyodin几乎一样,但是这里有一些重要的额外命令和信息。我试着编辑答案,但由于这是@yoyodin的答案的实质性变化,我的编辑被拒绝了,所以这是信息!
这种方法简单易懂,效果良好。脚本的参数($1)是一个引用(标签,散列,…),指向您想要保存历史记录的提交。
#!/bin/bash
git checkout --orphan temp $1 # create a new branch without parent history
git commit -m "Truncated history" # create a first commit on this branch
git rebase --onto temp $1 master # now rebase the part of master branch that we want to keep onto this branch
git branch -D temp # delete the temp branch
# The following 2 commands are optional - they keep your git repo in good shape.
git prune --progress # delete all the objects w/o references
git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos
注意,旧的标签将仍然存在;因此,您可能需要手动删除它们
备注:我知道这和@yoyodin几乎一样,但是这里有一些重要的额外命令和信息。我试着编辑答案,但由于这是@yoyodin的答案的实质性变化,我的编辑被拒绝了,所以这是信息!
当rebase或push到head/master时,可能会发生此错误
remote: GitLab: You are not allowed to access some of the refs!
To git@giturl:main/xyz.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@giturl:main/xyz.git'
要解决git仪表板中的这个问题,应该从“受保护的分支”中删除主分支
然后可以执行该命令
git push -f origin master
or
git rebase --onto temp $1 master