1

I'm working on a project in both Ubuntu WSL and Windows 10. I want to be able to edit the files in both windows 10 files system via sublime/...and in Ubuntu WSL via VScode/...and push changes to remote. I have noticed 2 issues when doing this:

  1. When I edit via VSCode on Ubuntu WSL, the file mode is changed to 755 and when I edit on windows the filemode changes to 644. So, every single commit has thousands of changes - just for the file executable bit change.

What should I do such that editing and pushing changes across windows filesystem and WSL filesystem retains the same mode?

Right now, I'm experimenting with using the below command every time I do a change via windows.

git add . --chmod=+x

(source: How to create file execute mode permissions in Git on Windows?) Is there a better way to handle this situation?

  1. Sometimes, the git diff shows the entire file being removed (i.e, all lines) and all lines added again. something like:
- print('hello')
+ print('hello')

I'm not sure why this happens.

I'm still learning Git and would like to know if what I'm doing is correct or if there are better ways to handle editing the same repo from different file systems.

user1934283
  • 124
  • 4
  • 15

1 Answers1

1

If you're storing a repository on a Windows file system, then it doesn't preserve Unix executable bits, and you'll need to rely on the --chmod flag to set those permission accordingly. If you store it only on a Linux file system and use the \\$wsl path notation under Windows, then the permissions will be preserved if (a) you stick to using the Linux Git binary and (b) your editor writes over existing files instead of writing to the side and renaming over the old one.

The reason you're seeing all the lines being modified is because one of your editors (probably the Windows one) is writing Windows line endings (CRLF) and the other is writing Unix line endings (LF). If you create a file in your repository called .gitattributes with the line * text=auto, then that will cause all the text files in your repository to be normalized with LF line endings when they're committed, which is generally what you want.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thank you for the explanation. For the lines modification issue, is using `git config --global core.autocrlf true` same as adding `* text=auto` to .gitattributes? – user1934283 Jan 09 '21 at 08:01
  • It's going to be a bit different, since that's going to force checkouts of CRLF in the working tree on Windows, which won't be the behavior on Linux, so you'll want to avoid doing that instead. – bk2204 Jan 09 '21 at 15:51
  • Thank you! Should I revert back to default by using `git config --global core.autocrlf false` ? – user1934283 Jan 09 '21 at 18:06
  • 1
    That's probably better if you're sharing across Windows and WSL. Most editors these days can handle any line ending, so using Unix line endings shouldn't be a problem, even in Windows. – bk2204 Jan 09 '21 at 18:09