5

私は今、ダイエットをしたいと思っている GitHub の大量のディスク容量を消費する、巨大で肥大化した Git リポジトリを持っています。プロジェクトの歴史の早い段階で行われた古いコミットを破棄する必要があります。これは、プロジェクトが進行している現在の方向性とは本質的に無関係です。

私は、そして今後もこのプライベート リポジトリの唯一のユーザーです。

理想的には、次のようなことができます。

git rebase from-birth-of-repo-until-1-month- ago

ありがとう、
ダグ

4

3 に答える 3

7

--squashオプションgit mergeは便利な場合があり、git1.4.1以降で使用できます。これにより、マージの効果がステージングされますが、コミットは作成されません。したがって、143effが押しつぶされたコミットに含める最も古いコミットであり、現在のブランチがmasterであり、「1か月前」のコミットが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.)

git diff dcb7e5 new-masterこれで、それらが実際に同じであることを確認できます。

次に、残りの作業をnew-masterにリベースします。

$ git rebase --onto new-master dcb7e5 master

それはあなたが望む歴史を持つべきであるリベースにあなたを残すでしょmasterう。(繰り返しますが、これはとで確認できますgit diff old-master master。マスターをgithubにプッシュするときは、履歴を書き換えたのでgit log追加する必要があります。--force

# Push master to github, with "--force", since you've rewritten history:
$ git push --force origin master

new-masterこれで、スカッシュコミットにあるを削除できます。

git branch -d new-master

どうやらgithubはgit gc --autoプッシュで実行されるので、すぐにスペースを節約できるはずです...

于 2010-07-28T11:55:10.913 に答える
2

実際、私は退屈な古いgit rebase -i HEAD〜Numberを使用します。ここで、Numberは私を頭から最初のコミットに戻します。もっと時間がかかりますが、少なくとも私はそれが何をしているのか漠然と理解しています。すべての提案をありがとう。

于 2010-07-28T15:53:49.960 に答える
1

Git 1.7.2 以降で動作するレシピを次に示します。

start=$starting_sha1
git checkout --orphan new_master $start
git commit -m '新しいルート'
git rebase --onto new_master $start マスター
git チェックアウト マスター
git リセット --hard new_master
git push -f オリジンマスター

reflog、stash、タグ、その他のブランチなどによって参照される可能性があるため、参照しなくなった古いオブジェクトを一掃するのはより多くの作業です。これらが修正または削除されたことを確認したら、次の 1 つ以上を実行する必要があります。ヘルプ:

gitプルーン
git gc
git repack -ad
于 2010-07-26T23:56:07.837 に答える