diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-11-23 22:31:51 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-11-23 22:31:51 -0800 |
commit | 444e10df2a4159b5dd2975feadbb9e1213d65b47 (patch) | |
tree | e0d4c7715d74c457f063c1b12105cf77cec60dae | |
parent | e61f25f3a6bb5dcbb5ae5f8b4ad26c308982373c (diff) | |
parent | e63ec003b2a0c89f0c1cbc4862dcef7c4a14a785 (diff) | |
download | git-444e10df2a4159b5dd2975feadbb9e1213d65b47.tar.gz git-444e10df2a4159b5dd2975feadbb9e1213d65b47.tar.xz |
Merge branch 'mm/maint-hint-failed-merge'
* mm/maint-hint-failed-merge:
user-manual: Document that "git merge" doesn't like uncommited changes.
merge-recursive: point the user to commit when file would be overwritten.
-rw-r--r-- | Documentation/config.txt | 4 | ||||
-rw-r--r-- | Documentation/user-manual.txt | 20 | ||||
-rw-r--r-- | advice.c | 2 | ||||
-rw-r--r-- | advice.h | 1 | ||||
-rw-r--r-- | merge-recursive.c | 8 |
5 files changed, 32 insertions, 3 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt index 657f0016d..a8e0876a2 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -126,6 +126,10 @@ advice.*:: Directions on how to stage/unstage/add shown in the output of linkgit:git-status[1] and the template shown when writing commit messages. Default: true. + commitBeforeMerge:: + Advice shown when linkgit:git-merge[1] refuses to + merge to avoid overwritting local changes. + Default: true. -- core.fileMode:: diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 27d97b6d1..b16983668 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -1183,7 +1183,23 @@ $ git merge branchname ------------------------------------------------- merges the development in the branch "branchname" into the current -branch. If there are conflicts--for example, if the same file is +branch. + +A merge is made by combining the changes made in "branchname" and the +changes made up to the latest commit in your current branch since +their histories forked. The work tree is overwritten by the result of +the merge when this combining is done cleanly, or overwritten by a +half-merged results when this combining results in conflicts. +Therefore, if you have uncommitted changes touching the same files as +the ones impacted by the merge, Git will refuse to proceed. Most of +the time, you will want to commit your changes before you can merge, +and if you don't, then linkgit:git-stash[1] can take these changes +away while you're doing the merge, and reapply them afterwards. + +If the changes are independant enough, Git will automatically complete +the merge and commit the result (or reuse an existing commit in case +of <<fast-forwards,fast-forward>>, see below). On the other hand, +if there are conflicts--for example, if the same file is modified in two different ways in the remote branch and the local branch--then you are warned; the output may look something like this: @@ -1679,7 +1695,7 @@ Sharing development with others Getting updates with git pull ----------------------------- -After you clone a repository and make a few changes of your own, you +After you clone a repository and commit a few changes of your own, you may wish to check the original repository for updates and merge them into your own work. @@ -2,6 +2,7 @@ int advice_push_nonfastforward = 1; int advice_status_hints = 1; +int advice_commit_before_merge = 1; static struct { const char *name; @@ -9,6 +10,7 @@ static struct { } advice_config[] = { { "pushnonfastforward", &advice_push_nonfastforward }, { "statushints", &advice_status_hints }, + { "commitbeforemerge", &advice_commit_before_merge }, }; int git_default_advice_config(const char *var, const char *value) @@ -3,6 +3,7 @@ extern int advice_push_nonfastforward; extern int advice_status_hints; +extern int advice_commit_before_merge; int git_default_advice_config(const char *var, const char *value); diff --git a/merge-recursive.c b/merge-recursive.c index baabe2c35..a91208f29 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3,6 +3,7 @@ * Fredrik Kuivinen. * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ +#include "advice.h" #include "cache.h" #include "cache-tree.h" #include "commit.h" @@ -171,7 +172,7 @@ static int git_merge_trees(int index_only, int rc; struct tree_desc t[3]; struct unpack_trees_options opts; - static const struct unpack_trees_error_msgs msgs = { + struct unpack_trees_error_msgs msgs = { /* would_overwrite */ "Your local changes to '%s' would be overwritten by merge. Aborting.", /* not_uptodate_file */ @@ -183,6 +184,11 @@ static int git_merge_trees(int index_only, /* bind_overlap -- will not happen here */ NULL, }; + if (advice_commit_before_merge) { + msgs.would_overwrite = msgs.not_uptodate_file = + "Your local changes to '%s' would be overwritten by merge. Aborting.\n" + "Please, commit your changes or stash them before you can merge."; + } memset(&opts, 0, sizeof(opts)); if (index_only) |