Reputation: 143
I've done a
git pull <some_url>
And a lot of files become in merge conflict state. How can i accept their changes using vscode or native git bash commands, without removing HEAD file by file?
Upvotes: 0
Views: 648
Reputation: 488213
First, remember that git pull
means:
git fetch
.git merge
.Both steps can fail, though typically step 1 usually succeeds and usually people get stuck in step 2. The way to get unstuck depends on which command you selected to use in step 2. So it's very important that you know which second command you had git pull
run for you. (This is one of many reasons I prefer to run each of the two commands separately, myself.)
You ran git pull
and step 1 succeeded, then—I assume based on your question—step 2 actually ran git merge
, and this is what failed. So you're now in the middle of a conflicted merge. In a conflicted merge, several Git commands will refuse to do anything. You must exit this conflicted state first! To do that, you have two options:
git merge --continue
or git commit
.git merge --abort
. This throws out any resolutions you have done so far!If you haven't done any work on resolving the merge, and just want to get out of the conflicted state, you can go ahead and use git merge --abort
. After doing that, there is no need to run git pull
again. It's just going to do the two steps—fetch
and then second-command—and the fetch
this time will have nothing to do. So now you can run a git merge
with options.
The simple command to use at this point is git merge -X theirs
. This uses your current branch's upstream setting—which git pull
itself also used—to retry the merge, but this time with the -X theirs
option. You can run git pull -X theirs
, and you can keep that in mind for future git pull
commands, but I'd recommend avoiding git pull
. Run the two separate commands separately, even though this means typing in two commands instead of one. That way you'll know for sure whether you're getting git merge
or git rebase
, and if and when the second command goes wrong, you'll know what to do—or at least what to ask—to get out of it.
Upvotes: 5
Reputation: 355
git pull -X theirs
See all the options: https://git-scm.com/docs/git-pull
Upvotes: 2