Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

sourcetree, git and line endings on windows (and visual studio)

mojmir svoboda September 10, 2014

hello,

recently i started using sourcetree, and i must say that this is a first gui for git that i really like. thank you!

but i have a big problem:

do you know how to set it up so that the sourcetree/git does works correctly with line endings?

 

what is happening:

i work on some files on windows project (i.e. mostly CRLF) with visual studio. some of the operations of sourcetree (stage/discard hunk? stashing? stage/discard line?) does messes with line endings in the way that when reloading the file in visual studio says that there are inconsistent line endings.

if i identify the file by file utility:

original file: C++ source, UTF-8 Unicode (with BOM) text, with CRLF line terminators

modified file: C source, UTF-8 Unicode (with BOM) text, with CRLF, LF line terminators

 

it does not happen often, but by now i "infected" at least 5 files in a project which annoys other users.

i watched it for a while and maybe i personally suspect stage line (s)/ discard selected line(s) functionality of sourcetree. but maybe i am wrong.

6 answers

1 vote
mojmir svoboda January 12, 2015
1 vote
sschilz January 7, 2015
0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2014

Looks like a bug, report it here.

0 votes
mojmir svoboda September 24, 2014

nah there's something more... it did it again while i watched, now i have 1oo% repro.

i have a file in stash, that has only one hunk in it. i can send it to you in form of patch, probably.

1) clean repository:

  $ file /d/src/lib/onExit.cpp

  /d/src/lib/onExit.cpp: C++ source, ASCII text, with CRLF line terminators

2) apply stash:

  $ file /d/src/lib/onExit.cpp

  /d/src/lib/onExit.cpp: C++ source, ASCII text, with CRLF line terminators

3) select green line

   discard green line by clicking at 'discard lines'

  $ file /d/src/lib/onExit.cpp

  /d/src/lib/onExit.cpp: C++ source, ASCII text, with CRLF line terminators

4) discard hunk

  $ file /d/src/lib/onExit.cpp

  /d/src/lib/onExit.cpp: C++ source, ASCII text, with CRLF, LF line terminators

 

 

0 votes
mojmir svoboda September 10, 2014

i do have that

PS D:\> git config --list | grep crlf
core.autocrlf=true
core.autocrlf=true
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2014

That will make sure that you don't "infect" more files later. For the already "infected" ones, you might need to fix the line endings once with a text editor and commit the change.

mojmir svoboda September 10, 2014

yes, but i have this setting for a very long time. and still observe new files with 'inconsistent line endings' appearing (after certain operations of git or sourcetree). that's why i am asking... i've been googling on this a lot. okay, i will fix the infected ones with unix2dos.exe and we'll see

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2014

You should set autocrlf = true.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events