diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-04-27 09:32:19 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-27 09:32:19 +0900 |
commit | af827b63f8c2886725683f1f538a4163beb046dd (patch) | |
tree | 4b28ae12901cd3bdcd10fa4d6d75d9baa4811003 /builtin/checkout.c | |
parent | 49800c940790cc7465d1b03e08d472ffd8684808 (diff) | |
download | git-jc/checkout-working-tree-only.tar.gz |
checkout: add --working-tree-only optionjc/checkout-working-tree-only
"git checkout <tree-ish> <pathspec>" has always copied the blob from
the tree-ish to the index before checking them out to the working tree.
Some users may want to grab a blob out of a tree-ish directly to the
working tree, without updating the index, so that "git diff" can be
used to assess the damage and adjust the file contents taken from a
different branch to be more appropriate for the current branch.
The new option "--working-tree-only" allows exactly that.
In the hindsight, when a command works on the working tree and/or
the index, the usual convention is:
- with no other option, the command works only on the working tree;
- with "--cached" option, the command works only on the index; and
- with "--index" option, the command works on both the working tree
and the index.
So we probably should have triggered the default behaviour under the
"--index" option, and triggered this "--working-tree-only" mode of
behaviour when "--index" option is not given. From the same point
of view, "git checkout --cached <tree-ish> <pathspec>" would have
done the same as "git reset <tree-ish> <pathspec>" would do. And
that may have made the command set a bit more consistent.
But that is merely a hindsight being 20/20, oh well.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 81f07c3ef2..5d583d6c96 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -37,6 +37,7 @@ struct checkout_opts { int overwrite_ignore; int ignore_skipworktree; int ignore_other_worktrees; + int no_index; int show_progress; const char *new_branch; @@ -268,6 +269,9 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("Cannot update paths and switch to branch '%s' at the same time."), opts->new_branch); + if (opts->no_index && !opts->source_tree) + die(_("'--working-tree-only' requires a tree-ish")); + if (opts->patch_mode) return run_add_interactive(revision, "--patch=checkout", &opts->pathspec); @@ -370,7 +374,9 @@ static int checkout_paths(const struct checkout_opts *opts, } } - if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) + if (opts->no_index) + ; /* discard the in-core index */ + else if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); read_ref_full("HEAD", 0, rev.hash, NULL); @@ -1164,6 +1170,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees, N_("do not check if another worktree is holding the given ref")), OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")), + OPT_BOOL(0, "working-tree-only", &opts.no_index, N_("checkout to working tree only without touching the index")), OPT_END(), }; |