문제

We have a centralized git repository that has a project only for Windows. So we expect autocrlf be false.

However, somebody also works on cross platform project and set

git config --global core.autocrlf true

If they forget to change the setting for this windows git repository, then they will commit unix ending file to it which is not expected by us.

So what i want is that: Regardless of how to set "git config --global core.autocrlf", autocrlf are always false when clone that repo and no need additional step to set it.

I know we can set core.autocrlf for local repo, but how it can be done for the remote repository?

도움이 되었습니까?

해결책

You can add and commit a .gitattributes file which sets eol=crlf for the files of types your require to have Windows EOLs (like *.cs, *.*proj etc).

Or may be just set

*       text=auto

in that file to have LFs in the repository and whatever your users wish in their work trees.

The exact approach depends on what is already in your repository.

By the way, the comments block in the .gitattributes file from the Mono project is particularly insightful about the EOL-normalization issues across different platforms.

다른 팁

You can make sure that your user have a GIT_TEMPLATE_DIR environment variable set to a "template directory" where you have a template git repo.

That template will be use when cloning or initializing a new repo, and can contain a custom template config file.

The question "Global git hook" illustrates how that template mechanisms can be use to pre-configure other aspects of a repo as well.

you could install a server-side hook that checks whether the line-endings are correct and refuses/fixes the problem centrally.

see this GIT CRLF hook for an example solution (though the other way round)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top