Re: Git terminology: remote, add, track, stage, etc.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ramkumar Ramachandra wrote:

> -- 
> 1.7.2.2.409.gdbb11.dirty

Please, one patch per message in the future.

> Sverre Rabbelier writes:
>> On Mon, Oct 18, 2010 at 15:45, Thore Husfeldt <thore.husfeldt@xxxxxxxxx> wrote:

>>> Â Â(use "git unstage <file>" to unstage)
>>
>> This would be extra nice since 'git unstage' could also be used in a
>> fresh repository.

My vague unhappiness at "git reset" may have come from this.

Wouldn't it make sense to make "git reset" basically a synonym for
"git rm --cached" when in the 'branch yet to be born' case?

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
diff --git a/builtin/reset.c b/builtin/reset.c
index 0037be4..cde103f 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -236,6 +236,7 @@ static void die_if_unmerged_cache(int reset_type)
 int cmd_reset(int argc, const char **argv, const char *prefix)
 {
 	int i = 0, reset_type = NONE, update_ref_status = 0, quiet = 0;
+	int unborn_branch = 0;
 	int patch_mode = 0;
 	const char *rev = "HEAD";
 	unsigned char sha1[20], *orig = NULL, sha1_orig[20],
@@ -299,13 +300,27 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (get_sha1(rev, sha1))
+	if (!strcmp(rev, "HEAD")) {
+		/* We may be on a branch yet to be born. */
+		resolve_ref("HEAD", sha1, 0, NULL);
+		if (is_null_sha1(sha1)) {
+			unborn_branch = 1;
+			commit = NULL;
+			hashcpy(sha1, (const unsigned char *) EMPTY_TREE_SHA1_BIN);
+
+			/* Only accept "git reset -- <paths>" form, for now. */
+			if (i == argc || patch_mode)
+				die("Failed to resolve 'HEAD' as a valid ref.");
+		}
+	} else if (get_sha1(rev, sha1))
 		die("Failed to resolve '%s' as a valid ref.", rev);
 
-	commit = lookup_commit_reference(sha1);
-	if (!commit)
-		die("Could not parse object '%s'.", rev);
-	hashcpy(sha1, commit->object.sha1);
+	if (!unborn_branch) {
+		commit = lookup_commit_reference(sha1);
+		if (!commit)
+			die("Could not parse object '%s'.", rev);
+		hashcpy(sha1, commit->object.sha1);
+	}
 
 	if (patch_mode) {
 		if (reset_type != NONE)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]