问题
I have a git repo and I generally work on it via my mac laptop. I had also cloned the repo on my windows laptop (using git bash
and cygwin
) earlier, everything was fine, but today when I took a git pull
I got several merge conflicts
though I had no local changes in my windows laptop.
I think it may be that the folders in mac use /
(forward slash) and in windows \
(backward slash) but I am not sure.
Can anyone tell me why this happened and how to resolve this?
回答1:
When working on the same repository from different operating systems you should define appropriate line endings on the repository level, or if you are the only user, configure your Git clients to do line ending conversions where needed. Examples here (Github) and here (official Git documentation).
What you most likely should do is configure CR+LF checkouts on windows
git config --global core.autocrlf true
and force LF on commit for Mac.
git config --global core.autocrlf input
Dealing with the whitespace differences on every merge is going to become annoying and cumbersome very fast.
回答2:
Folder separator in the pathes can't do that, git is enough smart in this sense.
The whitespaces differ:
- Mac uses different endline (
0x0d
instead of0x0d 0x0a
in windows) - Tabs may also differ, depending on the text editor setup (tab is
\t
on machine1 while it is 4-8 spaces on machine2)
The solution for this is the --ignore-all-space
flag, so:
git merge --ignore-all-space ...
来源:https://stackoverflow.com/questions/33574435/git-when-used-with-mac-and-windows-simultaneously-gives-unnecessary-conflicts