Search code examples
gitsettingsconflict

Eclipse Git Conflict at File Level


i have only used git via eclipse so not sure how to test this on the command line. i've only used git on two projects and both were intranet git repositories. On the first project a pull request would only fail if same line in a file was changed remotely and locally. On my current project i do a pull and it fails if the same file has been changed regardless of it being the same line changed (locally and remotely) or not. Is this a setting in the git repository or in eclipse?

Just to clarify, when i state "fail" i mean eclipse doesn't even attempt to do the pull and gives me a message about conflicts.

i do switch to new branch and do a local commit then switch back to master and pull then merge my temp branch. it isn't difficult but again,

i'm wondering why one project eclipse git would just pull down changes if a file had local and remote changes (as long as not the same line) but on my current project it will not attempt a pull if any file changes (even only different lines within file were changed.)

in my last project it didn't matter whether i had locally committed changes or not it would pull unless it was the same line in the same file.

for instance, i just now did a team->sync and saw files that were incoming so i just put a carriage return in the file and saved. instantly it showed in eclipse as a conflict. on my last project it would have not done that. it would have figure that the lines changes are different and it wouldn't have shown conflict. i'm thinking it is an eclipse setting.


update

a co-worker using the command line doesn't have the problem i am so i assume it is an eclipse setting. strange since i used eclipse on my last project. same version too. so i'll start looking at eclipse settings.


Solution

  • When you say pull fails I assume that you have made some changes to your local file but haven't committed it. Error description could be something like

    Please commit your changes or stash them before you merge

    If those changes are not important and you want to reverse back to the stage before the changes happen then do

    git reset HEAD YOUR_FILE
    #or
    git reset HEAD --hard
    

    If those changes to the file are what you want. You should commit the file before pull.

    git add YOUR_FILE
    git commit -m 'Updated the file'
    git push origin YOUR_BRANCH
    

    If you consider those changes as unfinished and don't want to commit something half-way done, you can move the changes to a stack to clean the working directory by using stash

    git status #check to see working directory state
    git stash #push a new stash onto your stack
    git stash list #see the stashes that you have stored
    git stash apply #to reapply your most recent stash
    #or 
    git stash apply YOUR_STASH_ID #to reapply a specific stash
    #or
    git stash pop #to apply the stash and then immediately drop it from your stack