diff options
| -rw-r--r-- | Documentation/git-checkout.txt | 2 | ||||
| -rw-r--r-- | builtin/checkout.c | 9 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 8c3d4128c2..3ea4579736 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -242,6 +242,8 @@ should result in deletion of the path). + When checking out paths from the index, this option lets you recreate the conflicted merge in the specified paths. ++ +When switching branches with `--merge`, staged changes may be lost. --conflict=<style>:: The same as --merge option above, but changes the way the diff --git a/builtin/checkout.c b/builtin/checkout.c index 24b8593b93..a56fa534f1 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -676,6 +676,8 @@ static int merge_working_tree(const struct checkout_opts *opts, struct tree *result; struct tree *work; struct merge_options o; + struct strbuf sb = STRBUF_INIT; + if (!opts->merge) return 1; @@ -686,6 +688,13 @@ static int merge_working_tree(const struct checkout_opts *opts, if (!old_branch_info->commit) return 1; + if (repo_index_has_changes(the_repository, + get_commit_tree(old_branch_info->commit), + &sb)) + warning(_("staged changes in the following files may be lost: %s"), + sb.buf); + strbuf_release(&sb); + /* Do more real merge */ /* |
