dug*_*gla 5 git github git-rebase
我现在有一个很大的鸣笛,臃肿的Git存储库在GitHub上占用了大量的磁盘空间我想要节食.我需要放弃在项目历史早期制作的古代承诺,这些承诺与项目目前的方向基本无关.
我 - 并将永远是 - 这个私人回购的唯一用户.
理想情况下,我可以这样做:
git rebase from-birth-repo-until-one-months-ago
谢谢,
道格
该--squash选项git merge可能很有用,可在git 1.4.1及更高版本中使用.这会分阶段合并的效果,但不会创建提交.所以,如果143eff你想要包含在压缩提交中的最早提交,你当前的分支是master"一个月前"提交dcb7e5,你可以这样做:
# Save the old position of "master" by creating a branch old-master:
$ git checkout master
$ git branch old-master
# Create and checkout a branch called "new-master" that's at the old commit:
$ git checkout -b new-master 143eff
# Stage the effects of merging the "one month ago" commit:
$ git merge --squash dcb7e5
Updating 143eff3..dcb7e5b
Fast-forward
Squash commit -- not updating HEAD
[... status output showing the staged changes ..]
# Create the squashed commit:
$ git commit -m "A commit squashing history up to a month ago"
# (You could use --amend if you want them to be squashed into 143eff
# instead of being a commit after that.)
Run Code Online (Sandbox Code Playgroud)
现在你可以检查git diff dcb7e5 new-master它们是否真的相同.
接下来,您希望将其余工作重新设置为new-master:
$ git rebase --onto new-master dcb7e5 master
Run Code Online (Sandbox Code Playgroud)
这将使你有一个master应该有你想要的历史的重新定位.(再次,您可以使用git diff old-master master和检查这个git log.当将master推送到github时,您需要添加,--force因为您已经重写了历史记录:
# Push master to github, with "--force", since you've rewritten history:
$ git push --force origin master
Run Code Online (Sandbox Code Playgroud)
你现在可以删除new-master,这是在壁球提交时,用:
git branch -d new-master
Run Code Online (Sandbox Code Playgroud)
显然github git gc --auto在推送时运行,所以你应该很快看到一些节省空间......
实际上,我会使用无聊的旧 git rebase -i HEAD~Number ,其中 Number 会带我从头部回到初始提交。更耗时,但至少我对它在做什么有一个模糊的了解。感谢所有的建议。
| 归档时间: |
|
| 查看次数: |
1809 次 |
| 最近记录: |