简体   繁体   中英

How can I set LF line endings for local git repository on Windows?

I got one problem with line endings in Git repository. I want to build my C++ program for Linux using Docker. The host system is Windows 10. But the first problem I got stuck with is line endings. Windows uses CRLF, but Linux uses LF line endings. How can I set my local repository to make LF line endings? I tried to set "core.autocrlf = false" and "eol = lf" in git config, but it had no effect. How can I resolve the problem with line endings?

Are you pulling the project onto Linux and building it there because if so you want to leave those configuration changes alone as they should convert line endings to lf.

The git configurations are about how line-endings are modified once the changes are committed and pushed to the repository (and then in turn if they're converted when pulling back from the repository). If you've been working on files in CLRF then git won't automatically change files line-endings just because you've changed the config. You should also look at writing new files in lf, most IDEs have ways of doing this.

If you're building on Windows though, provided you committed your files when autoclrf was true, the files within the git project repository should have lf endings, changing autoclrf=false and eol-lf should be enough, you just need to do a hard reset to make git bring your local in sync with the repository.

Look at some of the answers here: How do I force git to use LF instead of CR+LF under windows?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM