{"thread":{"id":"3695","subject":"Warning: fetch updated the current branch head.","startedAt":"2006-03-22T09:48:37Z","lastAt":"2006-03-22T09:48:37Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"17762","messageId":"7v4q1qajyi.fsf@assigned-by-dhcp.cox.net","threadId":"3695","inReplyTo":null,"subject":"Warning: fetch updated the current branch head.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-03-22T09:48:37Z","receivedAt":"2006-03-22T09:48:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I was helping somebody who:\n\n * had a clone of git.git repository;\n * had \"next\" checked out a week or so ago;\n * did not have any development on his own;\n * tried to pull using the default .git/remotes/origin from me.\n\nSomehow the index was out of sync before that pull but there was\nno change in the working tree (i.e. just the cached stat was\ndifferent), and it refused to fast-forward the index and the\nworking tree, because if there _were_ real changes in the\nworking tree, they would have been lost by a fast-forward.\n\nThis patch will be in \"next\" and does two things:\n\n * runs \"git update-index --refresh\" before the fast-forwarding,\n   to prevent stat-only difference from interfering;\n\n * if there really is a local change in the working tree, show\n   the original branch head information in the message, to allow\n   the user to decide what to do next.\n\nThe first one would have made his working tree to fast-forward\ncorrectly.  If the fast-forward is still prevented, that means\nthere really was a change, and in such a case, the way to recover\nwould be:\n\n * Examine \"git diff $orig_head\" output, to make sure there is\n   no local change since the last pull.  If there is none, you\n   can run \"git reset --hard\" (you do not have to name \"next\",\n   because that is the branch you are already on) and you are\n   done.\n\n * If there are local changes, stash them away as a patch,\n   \"git reset --hard\" and re-apply if they are precious.\n\nI've considered rewinding the tracking branch to match\n$orig_head in such a case just before \"die\", but that would be a\ndisservice to people behind a narrow pipe -- it would require\nthem to re-download the objects to update the branch.\n\nI now realize that the \"die\" message is a bit confusing, after\nwriting the above recovery procedure.  Especially, the new\n\"git-update-index --refresh\" would say \"foo: needs update\", but\n\"update your working tree\" does not mean \"git update-index foo\"\nafter such a failure.  Maybe this phrasing is better:\n\n\tdie 'Cannot fast-forward your working tree.\nAfter making sure that you saved anything precious from\n$ git diff '$orig_head'\noutput, and run \n$ git reset --hard\nto recover.'\n\nOpinions?\n\n-- >8 --\n[PATCH] git-pull: further safety while on tracking branch.\n\nRunning 'git pull' while on the tracking branch has a built-in\nsafety valve to fast-forward the index and working tree to match\nthe branch head, but it errs on the safe side too cautiously.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n git-pull.sh |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ncf46e7b8999f25d5d7f2acd64701a100e403ee03\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 29c14e1..d90f7c9 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -55,7 +55,9 @@ then\n \t# First update the working tree to match $curr_head.\n \n \techo >&2 \"Warning: fetch updated the current branch head.\"\n-\techo >&2 \"Warning: fast forwarding your working tree.\"\n+\techo >&2 \"Warning: fast forwarding your working tree from\"\n+\techo >&2 \"Warning: $orig_head commit.\"\n+\tgit-update-index --refresh 2>/dev/null\n \tgit-read-tree -u -m \"$orig_head\" \"$curr_head\" ||\n \t\tdie \"You need to first update your working tree.\"\n fi\n-- \n1.2.4.gfd45\n"}]}