Amanite Laurine
Amanite Laurine

Reputation: 1149

why git doesn't merge with modified files when pulling

let's suppose I edited the file "test.html". It is not in staging areas. I want to pull, but in HEAD this file is modified too. Git won't let me pull because it would "overwrite existing changes". I so have to make a stash to put my modifications on side, pull and get back my stash. my question is, why doesn't git merge test.html (supposely we didn't modify the same line and there is no conflict) ?

I wouldn't like to overwrite my current test.html, but merge it with HEAD without commit it

Upvotes: 0

Views: 61

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521997

What happens when you git pull is that one or more new commits are coming into your local branch, moving the HEAD of that branch forward. Your current working directory, to Git, can conceptually be thought of as a series of changes against the previous HEAD, before the pull happened. If the changes brought in by the pull would render the diff for test.html substantially different such that Git cannot easily figure out how to express it in terms of the new HEAD, then you would tend to get the error which you are seeing.

As far as I know, you might also have not gotten this error, if, for example, the area of test.html which you modified was not altered at all by the changes coming in from the pull.

It is generally good Git etiquette to not do a git pull when your working directly or stage are dirty. Rather, plan on pushing or pulling when they are both clean, you have made your commits, etc.

Upvotes: 3

Related Questions