git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] git-prune: never lose objects reachable from our refs.

From
Junio C Hamano <junkio@cox.net>
Date
Dec 9, 2005, 07:25 UTC
Message-ID
<7vmzja91gp.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7voe3r9krf.fsf@assigned-by-dhcp.cox.net>

Explicit <head> arguments to git-prune replaces, instead of extends, the list of heads used for reachability analysis by fsck-objects. By giving a subset of heads by mistake, objects reachable only from other heads can be removed, resulting in a corrupted repository.

This commit stops replacing the list of heads, and makes the command line arguments to add to them instead for safety.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * I think this is preferable in general than leaving the
   end-user tool too sharp-edged and dangerous.
 Documentation/git-prune.txt |   27 +++++++++------------------
 git-prune.sh                |    6 +++++-
 2 files changed, 14 insertions(+), 19 deletions(-)
2b86976bfd6e42609692d57fffaef72bd985c23a
diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt
index 05c8d49..f694fcb 100644
--- a/Documentation/git-prune.txt
+++ b/Documentation/git-prune.txt
@@ -13,10 +13,11 @@ SYNOPSIS
 DESCRIPTION
 -----------
 
-This runs `git-fsck-objects --unreachable` using the heads
-specified on the command line (or `$GIT_DIR/refs/heads/\*` and
-`$GIT_DIR/refs/tags/\*` if none is specified), and prunes all
-unreachable objects from the object database.  In addition, it
+This runs `git-fsck-objects --unreachable` using all the refs
+available in `$GIT_DIR/refs`, optionally with additional set of
+objects specified on the command line, and prunes all
+objects unreachable from any of these head objects from the object database.
+In addition, it
 prunes the unpacked objects that are also found in packs by
 running `git prune-packed`.
 
@@ -31,29 +32,19 @@ OPTIONS
 	Do not interpret any more arguments as options.
 
 <head>...::
-	Instead of keeping objects
+	In addition to objects
 	reachable from any of our references, keep objects
-	reachable from only listed <head>s.
-+
-Note that the explicitly named <head>s are *not* appended to the
-default set of references, but they replace them.  In general you
-would want to say `git prune $(git-rev-parse --all) extra1
-extra2` to keep chains of commits leading to extra1, extra2,
-... in addition to what are reachable from your own refs.
-Saying `git prune extra1 extra2` would *lose* objects reachable
-only from the usual refs, which is usually not what you want.
-
+	reachable from listed <head>s.
 
 EXAMPLE
 -------
 
-To prune objects not used by your repository and another that
+To prune objects not used by your repository nor another that
 borrows from your repository via its
 `.git/objects/info/alternates`:
 
 ------------
-$ git prune $(git-rev-parse --all) \
-  $(cd ../another && $(git-rev-parse --all))
+$ git prune $(cd ../another && $(git-rev-parse --all))
 ------------
 
 Author
diff --git a/git-prune.sh b/git-prune.sh
index 1fd8c73..7e7f0ad 100755
--- a/git-prune.sh
+++ b/git-prune.sh
@@ -16,7 +16,11 @@ do
 done
 
 sync
-git-fsck-objects --full --cache --unreachable "$@" |
+case "$#" in
+0) git-fsck-objects --full --cache --unreachable ;;
+*) git-fsck-objects --full --cache --unreachable $(git-rev-parse --all) "$@" ;;
+esac |
+
 sed -ne '/unreachable /{
     s/unreachable [^ ][^ ]* //
     s|\(..\)|\1/|p
-- 
0.99.9.GIT
Previous: Junio C HamanoNext: Peter Eriksen
Message 9 of 12 in “Documentation/git-commit.txt: Add long options and -- to documentation.”
  1. 4/17 Documentation/git-commit.txt: Add long options and -- to documentation.Nikolai Weibull, Dec 8, 2005
  2. 5/17 Documentation/git-verify-pack.txt: added documentation for --.Nikolai Weibull, Dec 8, 2005
  3. 6/17 Document the [<head>...] and -- arguments to git-prune.Nikolai Weibull, Dec 8, 2005
  4. 7/17 Documentation/git-cvsimport.txt: Fix a slight glitch in description heading.Nikolai Weibull, Dec 8, 2005
  5. 8/17 Documentation/git-cherry-pick: Add --replay and --no-commit.Nikolai Weibull, Dec 8, 2005
  6. Junio C HamanoDec 8, 2005
  7. Junio C HamanoDec 8, 2005
  8. Junio C HamanoDec 9, 2005
  9. git-prune: never lose objects reachable from our refs.Junio C Hamano, Dec 9, 2005
  10. Peter EriksenDec 9, 2005
  11. Junio C HamanoDec 9, 2005
  12. Nikolai WeibullDec 9, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.