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

[PATCH] git-reset: allow --soft in a bare repo

From
Jeff King <peff@peff.net>
Date
Jul 14, 2007, 04:49 UTC
Message-ID
<20070714044916.GA24911@coredump.intra.peff.net>

Previously, git-reset always required a work directory. For --mixed and --hard resets, this makes sense, as the bare repo doesn't have an index or a working tree. However, for --soft, there's no reason to prohibit this behavior.

Signed-off-by: Jeff King <peff@peff.net>
---
Somebody asked about this on irc ("how do I rewind history in a bare
repo"). The only other ways right now are to update the ref manually
(which involves plumbing), or to "git-push -f" from a non-bare
repository. I can't think of any good reason why a soft reset shouldn't
be allowed.
 git-reset.sh |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/git-reset.sh b/git-reset.sh
index 1dc606f..5450289 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -6,7 +6,6 @@ USAGE='[--mixed | --soft | --hard]  [<commit-ish>] [ [--] <paths>...]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 set_reflog_action "reset $*"
-require_work_tree
 
 update= reset_type=--mixed
 unset rev
@@ -32,6 +31,13 @@ do
 	shift
 done
 
+case "$reset_type" in
+	--soft)
+		;;
+	*)
+		require_work_tree
+esac
+
 : ${rev=HEAD}
 rev=$(git rev-parse --verify $rev^0) || exit
 
-- 
1.5.3.rc1.807.g51fb9-dirty
Next: Junio C Hamano
Message 1 of 5 in “git-reset: allow --soft in a bare repo”
  1. git-reset: allow --soft in a bare repoJeff King, Jul 14, 2007
  2. Junio C HamanoJul 14, 2007
  3. Jeff KingJul 14, 2007
  4. Junio C HamanoJul 14, 2007
  5. Jeff KingJul 15, 2007

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.