[ACCEPTED]-git pull from clean directory has merge conflicts-git
Your working directory may be clean, but 7 you have one or more commits that you have 6 made locally that are not on the server. When 5 you pull, git tries to merge these local 4 commits with the ones on the server, but 3 since they modify the same area of the code, they 2 conflict.
Your options here basically boil 1 down to:
- Fix the conflicts. You tell git how to handle the conflicting changes, and move on.
- Rebase and fix the conflicts, with
git pull --rebase. This is not much different from 1, but if your changes have never been published (ie, they've never been pushed, ever), this may get you a cleaner (linear) history.
- Discard your local changes and use the remote's, with
git reset --hard remotename/remotebranch. This will lose any changes you have committed locally but not pushed elsewhere.
Pull, resolve the merge conflicts and commit? Even 4 if you have a clean working directory, if 3 you have committed some work, that is conflicting 2 with the incoming changes, you get a merge 1 conflict.
Adding to bdonlan answer, it can happen when you 7 have some commits (on your local repository), but 6 the remote repository is ahead (had some 5 progress comparing to your local committed 4 files).
I just got stuck when I could not 3 push nor pull due to those conflicts.
Tried 2 to do 'rebase' or 'reset --hard' with no luck.
The only solution worked for me was to go back one commit and pull;
Follow the 1 next steps:
Warning: this is a destructive operation which will cause you losing your last changes to this code, so backup your changes first!
- Use 'git log' on your local repository and compare this to the commits log on the remote - to understand which one of your commits was not pushed
- Use 'git reset --hard' to go back to the last time your code fit to the remote repository (I used 'git reset --hard HEAD^' to deliberately lose my previous commit)
- Now 'git pull' will work; use it to get the latest code from the remote server
More Related questions