threads / discuss / 24432

Git Config Question

Subject: Git Config Question

## tl;dr

3 messages between Jul 19, 2010 and Aug 2, 2010.

replies: 2people: 3as markdown or json

Shilpa Kulkarni· Jul 19, 2010, 05:04 UTC · lore
Hi
We are using git with a centralized repo. Some of the developers are
on windows, some are on linux. The build system (ant & ruby scripts
are used for build) runs on linux. The server on which the software
product is deployed runs on linux. We see a frequent problem:
1. Person X clones a repo.
So far all is good.
2. Person Y checks in code (commit & push). Checks in file a, b.
3. Person X does a 'git pull origin master'. Pull succeeds - however
'git status' shows file a, b as modified even though person X has done
nothing with these files. 'git checkout' does not work. Files keep
getting showed as modified. If person X wants to commit any changes -
he is forced to commit file a & b.

This happens only sometimes - but it is frequent. It is not specific to whether Person Y was on linux or windows. Would having the right configs solve this problem? Any guidelines on what config we should use?

Someone has recommended we all use core.safecrlf=false core.autocrlf=false But this would require running dos2unix cmd while running scripts on linux which seems like an overhead.

Are these the only two configs that are important?
Any help is appreciated....
-Shilpa
Jonathan Nieder· Jul 19, 2010, 05:59 UTC · re: Shilpa Kulkarni · lore

Re: Git Config Question

(+cc: Eyvind Bernhardsen, Finn Arne Gangstad)
Hi!
Shilpa Kulkarni wrote:
Show 7 quoted lines
> 2. Person Y checks in code (commit & push). Checks in file a, b.
>
> 3. Person X does a 'git pull origin master'.
>
> Pull succeeds - however
> 'git status' shows file a, b as modified even though person X has done
> nothing with these files.
[...]
Show 5 quoted lines
> Someone has recommended we all use
> core.safecrlf=false
> core.autocrlf=false
> But this would require running dos2unix cmd while running scripts on
> linux which seems like an overhead.

I have not kept up with the latest best practices. But I suspect something like the following would work:

1. In .git/config, ~/.gitconfig, or /etc/gitconfig, on Windows:
	[core]
		autocrlf = true

See core.autocrlf in git-config(1). I think git for windows does this automatically.

2. In .git/config, ~/.gitconfig, or /etc/gitconfig, on Unix:
	[core]
		autocrlf = input
3. Convert line-endings in the tracked content.  Something like:
	$ git status; # make sure there are no untracked files present
	$ git rm -fr --cached .; # stop tracking all files
	$ git add .; # fix line-endings on all files
	$ git commit; # record that you have done so
4. Convert line-endings in the work tree.  Something like:
	$ git rm -fr .; # remove all tracked files
	$ git checkout HEAD -- .; # fetch them back again
5. In .gitattributes, something like:
	*	auto
	*.sh	crlf
	*.[ch]	crlf
	*.jpg	-crlf
See gitattributes(5) for details.

Hope that helps, Jonathan

Eyvind Bernhardsen· Aug 2, 2010, 19:13 UTC · re: Jonathan Nieder · lore

Re: Git Config Question

On 19. juli 2010, at 07.59, Jonathan Nieder wrote:
Show 9 quoted lines
> Shilpa Kulkarni wrote:
> 
>> 2. Person Y checks in code (commit & push). Checks in file a, b.
>> 
>> 3. Person X does a 'git pull origin master'.
>> 
>> Pull succeeds - however
>> 'git status' shows file a, b as modified even though person X has done
>> nothing with these files.
Sorry for the late reply.
The problem is that the files are checked in to the repository with CRLFs intact, but then checked out in a repository that has autocrlf enabled.  The result is that git wants to convert the files to LF, and shows them as modified even though no actual changes have been made.
This no longer happens with git 1.7.2: autocrlf will not convert files that contain CRLFs in the repository.  To enable forced conversion of text files containing CRLF with 1.7.2 or later, add this line to .gitattributes:
	*	text=auto
Files that need conversion (a and b in your example) should be checked in in the same commit as the change to .gitattributes.  gitattributes(5) has a recipe for making sure all files are converted.
Eyvind

← back to recent threads