Skip to contentSkip to conversation

reset: update help text

PATCH In review Nguyễn Thái Ngọc Duy 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reset: update help text

State --mixed is the default so users don't have to open up man page.

Also make it clear how --hard and --merge are different.

Move -q to bottom because it's not that important to pay attention to as the first item.

---
 builtin/reset.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
builtin/reset.c +3 -3
index eb5f98c..7419c9e 100644
@@ -243,17 +243,17 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	struct commit *commit;
 	char *reflog_action, msg[1024];
 	const struct option options[] = {
-		OPT__QUIET(&quiet, "be quiet, only report errors"),
 		OPT_SET_INT(0, "mixed", &reset_type,
-						"reset HEAD and index", MIXED),
+				"reset HEAD and index (default)", MIXED),
 		OPT_SET_INT(0, "soft", &reset_type, "reset only HEAD", SOFT),
 		OPT_SET_INT(0, "hard", &reset_type,
 				"reset HEAD, index and working tree", HARD),
 		OPT_SET_INT(0, "merge", &reset_type,
-				"reset HEAD, index and working tree", MERGE),
+				"like --hard but keep local changes in working tree", MERGE),
 		OPT_SET_INT(0, "keep", &reset_type,
 				"reset HEAD but keep local changes", KEEP),
 		OPT_BOOLEAN('p', "patch", &patch_mode, "select hunks interactively"),
+		OPT__QUIET(&quiet, "be quiet, only report errors"),
 		OPT_END()
 	};
 
Signature · 1 line
1.7.4.74.g639db
#1 lore raw

2011/3/29 Nguyễn Thái Ngọc Duy <[email protected]>:

Quoted 1 line

Also make it clear how --hard and --merge are different.

By the way I don't like the option names --hard, --mixed and --soft. They do not remind me what they actually do. Every time I need to do non-default operation, I have to open man page.

I've been thinking of --ref, --index and --worktree as a more friendly version, which can be combined and converted to --soft, --mixed and --hard internally. Invalid combinations will be rejected. That thinking went well until I found out there were --merge and --keep, and was stuck.

Signature · 1 line
Duy
#2 lore raw
In reply to Nguyễn Thái Ngọc Duy

(+cc: Christian, Michael, and Thomas)

Quoted 3 lines · Nguyễn Thái Ngọc Duy

State --mixed is the default so users don't have to open up man page.

Also make it clear how --hard and --merge are different.

Thanks; I think the goal of this patch is a good one.

builtin/reset.c int cmd_reset(int argc, const char **argv, const char *prefix) · line 247

Quoted 10 lines
builtin/reset.c +1 -2
@@ -243,17 +243,17 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	struct commit *commit;
 	char *reflog_action, msg[1024];
 	const struct option options[] = {
-		OPT__QUIET(&quiet, "be quiet, only report errors"),
 		OPT_SET_INT(0, "mixed", &reset_type,
-						"reset HEAD and index", MIXED),
+				"reset HEAD and index (default)", MIXED),

Nice.

builtin/reset.c int cmd_reset(int argc, const char **argv, const char *prefix) · line 254

Quoted 8 lines
builtin/reset.c +1 -1
 		OPT_SET_INT(0, "soft", &reset_type, "reset only HEAD", SOFT),
 		OPT_SET_INT(0, "hard", &reset_type,
 				"reset HEAD, index and working tree", HARD),
 		OPT_SET_INT(0, "merge", &reset_type,
-				"reset HEAD, index and working tree", MERGE),
+				"like --hard but keep local changes in working tree", MERGE),
 		OPT_SET_INT(0, "keep", &reset_type,
 				"reset HEAD but keep local changes", KEEP),

The description does not make it obvious to me how these two (--merge and --keep) differ. I think the intent of the options are:

--keep:
start working on a different commit, carrying over local changes (like "git checkout")
--merge:
return to <commit>, cancelling a merge-like operation that creates some unmerged and some clean index entries

Maybe something along these lines could be ok starting point?

	OPT_SET_INT(0, "keep", &reset_type,
		"move to <commit>, carrying over local changes in working tree",
		KEEP),
	OPT_SET_INT(0, "merge", &reset_type,
		"return to <commit>, cancelling failed merge or cherry-pick",
		MERGE),
#3 lore raw
Quoted 10 lines · Jonathan Nieder

The description does not make it obvious to me how these two (--merge and --keep) differ. I think the intent of the options are:

--keep:
start working on a different commit, carrying over local changes (like "git checkout")
--merge:
return to <commit>, cancelling a merge-like operation that creates some unmerged and some clean index entries

Quoted 8 lines

Maybe something along these lines could be ok starting point?

	OPT_SET_INT(0, "keep", &reset_type,
		"move to <commit>, carrying over local changes in working tree",
		KEEP),
	OPT_SET_INT(0, "merge", &reset_type,
		"return to <commit>, cancelling failed merge or cherry-pick",
		MERGE),

I cannot think of anything better, but I can still show my concern that "move to" and "return to" might not convey exactly what we are trying to express.

But I agree that your phrasing definitely is a good starting point.

#4 lore raw
In reply to Jonathan Nieder

2011/3/30 Jonathan Nieder <[email protected]>:

Quoted 10 lines

The description does not make it obvious to me how these two (--merge and --keep) differ.  I think the intent of the options are:

 --keep:
       start working on a different commit, carrying over local changes (like "git checkout")
 --merge:
       return to <commit>, cancelling a merge-like operation that creates some unmerged and some clean index entries

Quoted 9 lines

Maybe something along these lines could be ok starting point?

       OPT_SET_INT(0, "keep", &reset_type,
               "move to <commit>, carrying over local changes in working tree", KEEP),
       OPT_SET_INT(0, "merge", &reset_type,
               "return to <commit>, cancelling failed merge or cherry-pick", MERGE),

To be honest, I have no idea what the above describes. I read 9bc454d (reset: add option "--keep" to "git reset" - 2010-01-19) and figured that --keep is like --merge except that "git diff" before and after the reset is exactly the same, is it? I have never used --keep before.

Signature · 1 line
Duy
#5 lore raw
Quoted 4 lines · Nguyen Thai Ngoc Duy

To be honest, I have no idea what the above describes. I read 9bc454d (reset: add option "--keep" to "git reset" - 2010-01-19) and figured that --keep is like --merge except that "git diff" before and after the reset is exactly the same, is it? I have never used --keep before.

I use "git reset --keep" to

- discard a bad commit: git reset --keep HEAD^
- start working against a different commit:

	git checkout -b topic &&
	... hack hack hack without committing ... &&
	: "oops, I thought I was on master but I was somewhere else" &&
	git reset --keep master

The spirit of the thing[1] is:

* if the diff "HEAD -> <commit>" touch paths in which we have local changes, error out;
* otherwise, checkout the relevant paths from <commit> but leave the paths in which we have local changes alone.

which indeed means "git diff --cached" and "git diff" before and after would be exactly the same. But there are some edge cases, in which the diff "HEAD -> <commit>" makes the same change we did and the reset --keep is still allowed.

This is totally different from --merge. The only legitimate use of --merge is to cancel a merge you just performed, imho --- the effect otherwise is too scary ("git add <path>; git reset --merge elsewhere" --- bye, bye, changes made at <path>).

Hope that helps,
Jonathan

[1] Detailed semantics: for each path listed by "git diff --name-only HEAD <commit>":

* if the worktree, index, and HEAD match, make the index and worktree match <commit>.

* otherwise, if it is "not easy" to keep local changes, error out. We are not going to do a three-way merge. That is,

- if the index matches neither HEAD nor <commit>, error out;
- if the index matches HEAD but not the worktree, error out.

* otherwise, it is "easy", so keep local changes.

- if the index already matches <commit>, leave the index and worktree alone.
- if the index and worktree match HEAD, make them match the <commit> instead.

These are the same rules used by fast-forward merges and plain "git checkout".

#6 lore raw
Quoted 12 lines · Jonathan Nieder

[1] Detailed semantics: for each path listed by "git diff --name-only HEAD <commit>":

* if the worktree, index, and HEAD match, make the index and worktree match <commit>.

* otherwise, if it is "not easy" to keep local changes, error out. We are not going to do a three-way merge. That is,

- if the index matches neither HEAD nor <commit>, error out;
- if the index matches HEAD but not the worktree, error out.

Quoted 6 lines

* otherwise, it is "easy", so keep local changes.

- if the index already matches <commit>, leave the index and worktree alone.
- if the index and worktree match HEAD, make them match the <commit> instead.

The latter item in the last "otherwise" is the same as the first "if all match, move to the one from the named commit", isn't it?

#7 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Jonathan Nieder

[1] Detailed semantics: for each path listed by "git diff --name-only HEAD <commit>":

* if the worktree, index, and HEAD match, make the index and worktree match <commit>.

* otherwise, if it is "not easy" to keep local changes, error out. We are not going to do a three-way merge. That is,

- if the index matches neither HEAD nor <commit>, error out;
- if the index matches HEAD but not the worktree, error out.

* otherwise, it is "easy", so keep local changes.

Quoted 7 lines
Quoted 4 lines

- if the index already matches <commit>, leave the index and worktree alone.
- if the index and worktree match HEAD, make them match the <commit> instead.

The latter item in the last "otherwise" is the same as the first "if all match, move to the one from the named commit", isn't it?

Yes, sorry for the nonsense.

#8 lore raw
In reply to Jonathan Nieder
Quoted 12 lines · Jonathan Nieder
Quoted 4 lines · Nguyen Thai Ngoc Duy

To be honest, I have no idea what the above describes. I read 9bc454d (reset: add option "--keep" to "git reset" - 2010-01-19) and figured that --keep is like --merge except that "git diff" before and after the reset is exactly the same, is it? I have never used --keep before.

I use "git reset --keep" to

 - discard a bad commit: git reset --keep HEAD^
 - start working against a different commit:

Quoted 6 lines

       git checkout -b topic &&
       ... hack hack hack without committing ... &&
       : "oops, I thought I was on master but I was somewhere else" && git reset --keep master

..

Thanks. Your changes make sense to me now.

Signature · 1 line
Duy