Skip to content

Commit 3feaacb

Browse files
committed
Merge branch 'nd/checkout-m-doc-update'
Doc about the above. * nd/checkout-m-doc-update: checkout.txt: note about losing staged changes with --merge
2 parents e9bd21c + a7256de commit 3feaacb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Documentation/git-checkout.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ should result in deletion of the path).
242242
+
243243
When checking out paths from the index, this option lets you recreate
244244
the conflicted merge in the specified paths.
245+
+
246+
When switching branches with `--merge`, staged changes may be lost.
245247

246248
--conflict=<style>::
247249
The same as --merge option above, but changes the way the

builtin/checkout.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
726726
struct tree *result;
727727
struct tree *work;
728728
struct merge_options o;
729+
struct strbuf sb = STRBUF_INIT;
730+
729731
if (!opts->merge)
730732
return 1;
731733

@@ -736,6 +738,13 @@ static int merge_working_tree(const struct checkout_opts *opts,
736738
if (!old_branch_info->commit)
737739
return 1;
738740

741+
if (repo_index_has_changes(the_repository,
742+
get_commit_tree(old_branch_info->commit),
743+
&sb))
744+
warning(_("staged changes in the following files may be lost: %s"),
745+
sb.buf);
746+
strbuf_release(&sb);
747+
739748
/* Do more real merge */
740749

741750
/*

0 commit comments

Comments
 (0)