git reset '-' will reset to the previous branch. To reset a file named "-" use either "git reset ./-" or "git reset -- -". Change error message to treat single "-" as an ambigous revision or path rather than a bad flag. Helped-by: Junio C Hamano <gitster@xxxxxxxxx> Helped-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx> Helped-by: Matthieu Moy <Matthieu.Moy@xxxxxxxxxxxxxxx> Signed-off-by: Sudhanshu Shekhar <sudshekhar02@xxxxxxxxx> --- I have changed the logic to ensure argv[0] isn't changed at any point. Creating a modified_argv0 variable let's me do that. I couldn't think of any other way to achieve this, apart from changing things directly in the sha1_name.c file (like Junio's changes). Please let me know if some further changes are needed. builtin/reset.c | 17 +++++++++++++---- setup.c | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index 4c08ddc..bc50e14 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -192,6 +192,7 @@ static void parse_args(struct pathspec *pathspec, { const char *rev = "HEAD"; unsigned char unused[20]; + const char *modified_argv0 = argv[0]; /* * Possible arguments are: * @@ -205,10 +206,17 @@ static void parse_args(struct pathspec *pathspec, */ if (argv[0]) { + if (!strcmp(argv[0], "-")) { + modified_argv0 = "@{-1}"; + } + else { + modified_argv0 = argv[0]; + } + if (!strcmp(argv[0], "--")) { argv++; /* reset to HEAD, possibly with paths */ } else if (argv[1] && !strcmp(argv[1], "--")) { - rev = argv[0]; + rev = modified_argv0; argv += 2; } /* @@ -216,14 +224,15 @@ static void parse_args(struct pathspec *pathspec, * has to be unambiguous. If there is a single argument, it * can not be a tree */ - else if ((!argv[1] && !get_sha1_committish(argv[0], unused)) || - (argv[1] && !get_sha1_treeish(argv[0], unused))) { + else if ((!argv[1] && !get_sha1_committish(modified_argv0, unused)) || + (argv[1] && !get_sha1_treeish(modified_argv0, unused))) { /* * Ok, argv[0] looks like a commit/tree; it should not * be a filename. */ verify_non_filename(prefix, argv[0]); - rev = *argv++; + rev = modified_argv0; + argv++; } else { /* Otherwise we treat this as a filename */ verify_filename(prefix, argv[0], 1); diff --git a/setup.c b/setup.c index 979b13f..b621b62 100644 --- a/setup.c +++ b/setup.c @@ -200,7 +200,7 @@ void verify_filename(const char *prefix, int diagnose_misspelt_rev) { if (*arg == '-') - die("bad flag '%s' used after filename", arg); + die("ambiguous argument '%s': unknown revision or path", arg); if (check_filename(prefix, arg)) return; die_verify_filename(prefix, arg, diagnose_misspelt_rev); -- 2.3.1.277.gd67f9d5.dirty -- 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