Git pull - Resolve conflicts using remote changes when pulling from Git remote

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m trying to pull code from my GitHub repo onto my server, but the pull keeps failing because of merge conflicts. I don t want to keep any of the changes that may have occurred on my local server since the last pull.

So is there a way I can force Git to overwrite with whatever version is in GitHub, rather than bother me about conflicts?

Answers


If you truly want to discard the commits you ve made locally, i.e. never have them in the history again, you re not asking how to pull - pull means merge, and you don t need to merge. All you need do is this:

# fetch from the default remote, origin
git fetch
# reset your current branch (master) to origin s master
git reset --hard origin/master

I d personally recommend creating a backup branch at your current HEAD first, so that if you realize this was a bad idea, you haven t lost track of it.

If on the other hand, you want to keep those commits and make it look as though you merged with origin, and cause the merge to keep the versions from origin only, you can use the ours merge strategy:

# fetch from the default remote, origin
git fetch
# create a branch at your current master
git branch old-master
# reset to origin s master
git reset --hard origin/master
# merge your old master, keeping "our" (origin/master s) content
git merge -s ours old-master

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4785107/resolve-conflicts-using-remote-changes-when-pulling-from-git-remote

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils