Changing branches in git mistakenly leads to modified files

I am using git (1.8.3) on Windows. If I clone a repo from github, immediately check out another existing branch on that repo, git detects the modified files. Usually. This is sometimes not the case. And diff on all modified files is returned identically (including line endings). This problem was observed in two different repositories, at least on 4 different computers among my team.

And these are not always the same files, but they are almost always one of several subsets of files in rep. For example, sometimes these are the same 5 files in the root of the repo, sometimes they are the same 93 files in one particular folder, sometimes they are the same 16 files in another folder.

As soon as git has marked the files as changed, if I return them or run them, they will immediately be marked as changed again, which makes it impossible to switch between branches.

I have the feeling that it is connected to line ends, but I already added the recommended .gitattributes file and renormalized each branch, but I still have these sporadic problems. Another possibility that I was thinking about is merging between branches, somehow messed up the renormalization I did, but I donโ€™t know how to test this theory.

We all have core.autocrlf=true , since we are all on Windows. Here are our .gitattributes

 # Auto detect text files and perform LF normalization * text=auto # Custom for Visual Studio *.cs diff=csharp *.sln merge=union *.csproj merge=union *.sqlproj merge=union *.html text diff=html *.css text *.js text *.ejs text *.sql text # Standard to msysgit *.doc diff=astextplain *.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.pdf diff=astextplain *.PDF diff=astextplain 
+4
source share
2 answers

There are two situations when I saw such things:

  • Line endings and all the crazy Git options are designed to deal with these platforms. (I donโ€™t use these functions at all, and I prefer to store and work with files, all with consecutive LF line endings, including on Windows.)

  • Vaults that have two or more files whose names differ only in the case. For example, readme.txt and readme.txt . Git on Windows is very difficult to handle these situations, because there is only one base file that can be accessed through two different names.

+4
source

Never set core.autocrlf to true , always false .

It is simple: it is a global installation with unintended consequences.

If you have certain types of documents that you want to manage in terms of eol, do this only through .gitattributes files and core.eol .

This means: first get rid of changing the directory automatically eol (for example, your * text=auto ), push this modification back to the repository up and see if the problem persists.

Then, and only then, re-enter these directives, not for all files (not for ' * '), but only for files that you absolutely want to normalize to normal. And check if this works.

+2
source

Source: https://habr.com/ru/post/1500329/


All Articles