← 返回命令列表

Linux command

git-prune 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Prune unreachable

git prune

Dry run

git prune -n

Verbose

git prune -v

Only prune objects

git prune --expire=2.weeks.ago

Prune everything

git prune --expire=now

Keep objects reachable

git prune -- [refs/heads/topic]

说明

git prune removes loose objects from `.git/objects` that are not reachable from any reference. Objects become unreachable when commits are amended, rebased away, branches deleted, or stashes dropped, leaving dangling content in the object database. The command is normally invoked indirectly through git gc, which sets an appropriate --expire time (the `gc.pruneExpire` config, defaulting to `2.weeks.ago`) so that very recent objects are kept around for safety. The expiry window protects concurrent operations and recently created objects that the reflog has not yet started referencing. Note that git prune only touches loose objects. Unreachable objects already inside a packfile are removed by git repack -A.

参数

-n, --dry-run
Do not remove anything, just report what would be removed.
-v, --verbose
Report all removed objects.
--progress
Show progress while pruning.
--expire _time_
Only prune loose objects older than _time_ (e.g. `now`, `2.weeks.ago`).
--
Treat the remaining arguments as heads rather than options.

FAQ

What is the git-prune command used for?

git prune removes loose objects from `.git/objects` that are not reachable from any reference. Objects become unreachable when commits are amended, rebased away, branches deleted, or stashes dropped, leaving dangling content in the object database. The command is normally invoked indirectly through git gc, which sets an appropriate --expire time (the `gc.pruneExpire` config, defaulting to `2.weeks.ago`) so that very recent objects are kept around for safety. The expiry window protects concurrent operations and recently created objects that the reflog has not yet started referencing. Note that git prune only touches loose objects. Unreachable objects already inside a packfile are removed by git repack -A.

How do I run a basic git-prune example?

Run `git prune` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -n, --dry-run do in git-prune?

Do not remove anything, just report what would be removed.