Tell Git to stop prompting me for conflicts when n

2019-07-21 11:50发布

问题:

In the image below, all the files listed by Git are the same exact files that are remote. I used SCP to copy them to BSD for testing before committing. Once the platform tested OK, I committed on another machine:

I can't stress enough that these files are exactly the same, no conflict exists, and there is nothing to merge.

I tried to use git pull -s theirs, but I got an error about non-existent merging strategies.

I can't use git reset --hard HEAD because I have other changes that are in a different phase of testing.

How do I tell Git to stop prompting me about conflicts when none exists?

回答1:

Being certain that there are no textual differences in the files doesn't necessarily mean that there are no differences at all and no conflicts isn't the same thing as no differences.

These differences can be anything. Filename case re-mapping (I've seen this when working with code on the non-case-sensitive Apple filesystem) to permission changes, to the difference in line endings between what's in the file and what's expected to differences in file timestamps.

The first thing to start with is always git fetch origin to ensure your local ref store is fully up to date and then git diff origin/branch and look at why git thinks there are differences.

Do this from the terminal and not from an IDE. Depending on which IDE you use, they sometimes silently re-write line endings in the background which will only add to the confusion.

If, as you explain, there are no text differences, it's usually pretty safe to reset back to the origin head but (and there is a caveat), if you have something re-mapping files, perhaps in your git config (altering permissions, changing line-endings, etc.) or filesystem modifying permissions, then there is nothing to prevent this from re-occurring.

Look for what is happening first, then look for why it's happening. Without seeing your git configuration, workflow and difference outputs, it's hard to say with any certainty where the changes are coming from.



回答2:

If you are certain that the above set of files have no differences versus the remote, then you try resetting each of the files to the HEAD of your branch. After this, you can go a git pull and see what happens. Either the pull will go smoothly, or you could end up with a merge conflict.

git checkout -- algparam.h
git checkout -- basecode.cpp
...
git checkout -- wake.cpp

Followed by what you were already doing:

git pull origin master


标签: git git-merge