Skip to content

Commit 3a733ce

Browse files
pcloudsgitster
authored andcommitted
restore: default to --source=HEAD when only --staged is specified
"git restore --staged" without --source does not make much sense since by default we restore from the index. Instead of copying the index to itself, set the default source to HEAD in this case, yielding behavior that matches "git reset -- <paths>". Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3ddd3b commit 3a733ce

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

builtin/checkout.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,12 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15241524
}
15251525
if (opts->checkout_index < 0 || opts->checkout_worktree < 0)
15261526
BUG("these flags should be non-negative by now");
1527+
/*
1528+
* convenient shortcut: "git restore --staged" equals
1529+
* "git restore --staged --source HEAD"
1530+
*/
1531+
if (!opts->from_treeish && opts->checkout_index && !opts->checkout_worktree)
1532+
opts->from_treeish = "HEAD";
15271533

15281534
/*
15291535
* From here on, new_branch will contain the branch to be checked out,

0 commit comments

Comments
 (0)