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

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

i do have that

PS D:\> git config --list | grep crlf
core.autocrlf=true
core.autocrlf=true

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.

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

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

 

 

Looks like a bug, report it here.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

713 views 3 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you