git ウェアハウスのクリーンアップ
この記事では、ストレージ容量を最適化し、パフォーマンスを向上させるために、Git リポジトリから不要なファイルを特定して削除するための戦略とツールを提供します。ここで説明する主な問題は、未解決オブジェクト、大きなファイル、および untr の蓄積です
不要なファイルの特定と削除
git リポジトリから不要なファイルを特定して削除するには、次の手順に従います:
-
Run git gc --prune を使用して未解決オブジェクトを削除します:
git gc --prune
to remove dangling objects: This command removes objects that are unreachable from any commit. Dangling objects can accumulate over time when you delete branches or commits. -
Use
git filter-branch
to rewrite history: This command allows you to remove or modify specific files from the entire history of a branch. However, it's important to proceed cautiously as it rewrites the history of the repository. -
Check for large files: Large files can take up a significant amount of repository space. Use
git ls-files -s
to identify large files and consider moving them to a separate location. -
Review untracked files: Untracked files are not part of any commit and can be safely removed. Use
git clean -n
to list untracked files andgit clean -f
to remove them.
Best Practices for Cleanup After Merge or Branch Deletion
After a merge or branch deletion, follow these cleanup best practices:
-
Remove merged branches: After merging a branch, delete the merged branch to avoid clutter. Use
git branch -d <branch-name>
to delete the branch. -
Delete remote branches: If you have deleted a branch locally but it still exists on the remote repository, delete it remotely using
git push <remote-name> --delete <branch-name>
. -
Prune the reflog: The reflog records all actions made to the repository. Use
git reflog expire --expire=<duration>
to prune old entries in the reflog. -
Reset HEAD: If you want to revert the repository to a specific commit, use
git reset --hard <commit-hash>
このコマンドは、どのコミットからも到達できないオブジェクトを削除します。ブランチやコミットを削除すると、ダングリング オブジェクトが時間の経過とともに蓄積される可能性があります。
git filter-branch
を使用して履歴を書き換えます:
このコマンドを使用すると、ブランチの履歴全体から特定のファイルを削除または変更できます。ただし、リポジトリの履歴が書き換えられるため、慎重に作業を進めることが重要です。
- 大きなファイルを確認する:
- 大きなファイルは、大量のリポジトリ領域を占有する可能性があります。
git ls-files -s
を使用して大きなファイルを特定し、別の場所に移動することを検討してください。 追跡されていないファイルを確認する: - 追跡されていないファイルはコミットの一部ではないため、安全に削除できます。
git clean -n
を使用して追跡されていないファイルをリストし、git clean -f
を使用してそれらを削除します。 マージまたはブランチ削除後のクリーンアップのベスト プラクティス - マージまたはブランチの削除後ブランチを削除する場合は、次のクリーンアップのベスト プラクティスに従ってください:
-
マージされたブランチを削除する: ブランチをマージした後、混乱を避けるためにマージされたブランチを削除します。ブランチを削除するには、
git Branch -d <branch-name>
を使用します。
git Push を使用します。 --delete <branch-name>
.🎜🎜🎜reflog をプルーニングします:🎜 reflog は、リポジトリに対して行われたすべてのアクションを記録します。 reflog 内の古いエントリを削除するには、git reflogexpire --expire=<duration>
を使用します。🎜🎜🎜Reset HEAD:🎜 リポジトリを特定のコミットに戻したい場合は、 を使用します。 git replace --hard <commit-hash>
。これにより、コミットされていない変更がすべて削除され、指定されたコミットが新しい HEAD になります。🎜🎜🎜自動クリーンアップ ツール🎜🎜 git リポジトリのクリーンアップ プロセスを自動化するために利用できるツールとスクリプトがいくつかあります:🎜🎜🎜🎜git-cleanup:🎜 コマンド-追跡されていないファイル、空のディレクトリ、reflog の削除など、さまざまなクリーンアップ コマンドを提供するライン ツール。🎜🎜🎜git-prune:🎜 未解決のコミット、タグ、ブランチを削除するのに役立つシェル スクリプト。🎜🎜🎜git-スイープ: 🎜 Git リポジトリから参照されていない大きなファイルを識別して削除する Ruby スクリプト。🎜🎜🎜git-annex:🎜 大きなファイルを追跡しながらメイン リポジトリから移動できるツール。🎜🎜以上がgit ウェアハウスのクリーンアップの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undress AI Tool
脱衣画像を無料で

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Stock Market GPT
AIを活用した投資調査により賢明な意思決定を実現

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

古いコミットから新しいブランチを作成するには、最初にターゲットコミットのハッシュ値を見つけ、次にGitcheckout-BまたはGitswitch-Cコマンドを使用してブランチを作成し、最後にブランチが正しく生成されていることを確認します。具体的な手順は次のとおりです。1。gitlogを使用して、commitハッシュを見つけるか、gitlog-s "keyword"を使用して特定のコミットを見つけます。 2。gitcheckout-b new Branch name submission hashまたはgitswitch-c new branch name submission hash branchを作成するために、gitは略されたハッシュをサポートします。 3. GitlogとGitbranchを介してブランチ情報を確認し、ファイルのコンテンツを確認して、正しさを確保します。プロセス全体はシンプルで信頼性が高く、習熟後に行うことができます。

usegitlogwith- all、 - full-history、および - diff-filtertofindcommitsinvoltedorededisingingfilebyname、その後、grepforthefilenametoidefidoideidiforrevantcommits;

rungit - versiontocheckinStalledgitversion、withoutputslikegitversion2.34.1; usegitversion-vforslightlightlymoredetail; ifgitis notが認識し、保証することを保証します

gitpull - rebaseを使用して、リモートで更新されたブランチの上部にローカルコミットを再適用し、冗長なマージコミットの生成を回避し、線形履歴を維持します。実行中に、ローカルの提出が一時的に保存され、最新の変更が引かれ、ローカル提出が1つずつ再生されます。競合が発生した場合は、手動で解決し、gitrebaseを実行する必要があります - 継続するか、gitrebaseで終了します。非共有機能のブランチでのみ使用し、メインなどの一般的なブランチの再加行を避け、共同作業者に影響を与えることを防ぐことをお勧めします。 Rebaseは、gitconfig設定でデフォルトで有効にすることができます。操作の前に、最初にGitFetchが最新情報を保証して、クリーンな履歴を維持し、変更をタイムリーに同期させる必要があります。

usegitarchiveTocreateaCompressedsnapshotOfarepositoryataspificcommit、除外、gitmetadata.rungitarchive - format = zip- outpu t = repo-archive.zipheadtopackagetheTheLatestCommitIntoAzipfile、orusetar.gzforatarball.add ---prefix = myproject-v1.0/to includeadirect

settheupstreamremotewith "gitremoteaddupstream [url]" tolinkyourforktotheoriginalrepository.2.fetchchanges fromupstreamusing "gitfetchupstream" todownloadthelatestupdates.3.3.mergethemintoyourlanchwith "gitcheckoutmain" gitcheckoutmain "

gitdiff-tree - name-only-rを使用して、指定された提出物のすべての変更ファイルをリストします。 -name-statusを追加してファイルステータス(a/m/d)を表示します。これは、スクリプト処理に適しており、出力が簡潔です。

usegitlog - author = "authorname" tofiltercommitsbyauthor、partialmatcheSandemailsearchesをサポートし、oneoptionalformattinglike - oneLineforClearerOutput。
