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

Re: Simplify "git reset --hard"

From
Linus Torvalds <torvalds@osdl.org>
Date
May 15, 2006, 15:09 UTC
Message-ID
<Pine.LNX.4.64.0605150807030.3866@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0605150752490.3866@g5.osdl.org>
On Mon, 15 May 2006, Linus Torvalds wrote:
Show 5 quoted lines
> 
> Ack. On the other hand, I wonder if it might not make sense to have this 
> part potentially depend on the "--reset" flag.
> 
> That way you wouldn't even have to apologize for it.
Ie, something like this..

This should allow a two-way or three-way merge to akso ignore any dirty state when you use "--reset", because they use "verify_uptodate()", which now would set the CD_UPDATE flag on the ce rather than complain about it being different (if it survives the merge, of course - often it won't, but then we won't care).

This is all totally untested, of course.
		Linus
----
diff --git a/read-tree.c b/read-tree.c
index 7c83031..f2d674c 100644
--- a/read-tree.c
+++ b/read-tree.c
@@ -13,6 +13,7 @@ #include "cache-tree.h"
 #include <sys/time.h>
 #include <signal.h>
 
+static int reset = 0;
 static int merge = 0;
 static int update = 0;
 static int index_only = 0;
@@ -419,6 +420,10 @@ static void verify_uptodate(struct cache
 			return;
 		errno = 0;
 	}
+	if (reset) {
+		ce->ce_flags |= htons(CE_UPDATE);
+		return;
+	}
 	if (errno == ENOENT)
 		return;
 	die("Entry '%s' not uptodate. Cannot merge.", ce->name);
@@ -723,6 +728,11 @@ static int oneway_merge(struct cache_ent
 		return deleted_entry(old, NULL);
 	}
 	if (old && same(old, a)) {
+		if (reset) {
+			struct stat st;
+			if (lstat(old->name, &st) || ce_match_stat(old, &st, 1))
+				old->ce_flags |= htons(CE_UPDATE);
+		}
 		return keep_entry(old);
 	}
 	return merged_entry(a, NULL);
@@ -790,7 +800,7 @@ static struct cache_file cache_file;
 
 int main(int argc, char **argv)
 {
-	int i, newfd, reset, stage = 0;
+	int i, newfd, stage = 0;
 	unsigned char sha1[20];
 	merge_fn_t fn = NULL;
 
Previous: Linus Torvalds
Message 8 of 8 in “Allow one-way tree merge to remove old files”
  1. Linus TorvaldsMay 14, 2006
  2. Junio C HamanoMay 14, 2006
  3. Simplify "git reset --hard"Linus Torvalds, May 14, 2006
  4. Junio C HamanoMay 15, 2006
  5. Junio C HamanoMay 15, 2006
  6. Junio C HamanoMay 15, 2006
  7. Linus TorvaldsMay 15, 2006
  8. Linus TorvaldsMay 15, 2006

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.