Skip to content

Commit

Permalink
restore: default to --source=HEAD when only --staged is specified
Browse files Browse the repository at this point in the history
"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]>
  • Loading branch information
pclouds authored and gitster committed May 7, 2019
1 parent e3ddd3b commit 3a733ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
@@ -1524,6 +1524,12 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
}
if (opts->checkout_index < 0 || opts->checkout_worktree < 0)
BUG("these flags should be non-negative by now");
/*
* convenient shortcut: "git restore --staged" equals
* "git restore --staged --source HEAD"
*/
if (!opts->from_treeish && opts->checkout_index && !opts->checkout_worktree)
opts->from_treeish = "HEAD";

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

0 comments on commit 3a733ce

Please sign in to comment.