What is the best git config set up when you are using Linux and Windows? - linux

I am a bit confused with core.eol, core.autocrlf, core.safecrlf for git config.
http://git-scm.com/docs/git-config
I am using Ubuntu and Widows.
I had ^M, and other issues before.
Could anyone suggest the best git config setups for this problem?
Thanks in advance.

As detailled in Git on Windows (msysgit) - Unix or DOS line termination, I would use:
git config --system core.autocrlf false
That would avoid any automatic eol transformation (See "Git on Windows: What do the crlf settings mean?" for the exact meaning of this option value).
You can leave it to true, as explained in git replacing LF with CRLF, but I prefer setting core.eol + some gitattribute files in order to fine tune some of the files I want eol changes on.
See this answer for more details.

Related

There are some changes opening in the linux of a git repo. But the repo is latest in windows

My pc is a dual system with Linux Mint and Windows 11.
The git repo always has some changes in Linux.
Every time I need to git stash and git stash drop.
I don't know how to descript this situation with google.
Help pls. Thanks.
The problem is that you have different line ending settings between Linux and Windows. What you're seeing in Linux is that your files have carriage returns on the end of them, which is the Windows line ending.
The easiest way to solve this is to add this to .gitattributes:
* text=auto
Then, on an otherwise empty working tree, add that file, run git add --renormalize ., and commit. That will cause the files to be renormalized as having LF line endings in the index.
If you're going to be working across OSes, then you'd also do well to add eol=lf to the end of that line in .gitattributes so that files are always handled with LF endings. You'll also need to configure your tools on Windows to emit LF endings instead of CRLF endings. That will prevent line ending differences in the working tree across systems.

git - CRLF issue in windows + linux dual boot

I'm going to answer my question with the fix what solved my problem.
Note for downvoters: I understand that the root cause is discussed in various other threads (that is how I solved my problem). This post is more about how having a dual boot system can lead you to this issue. So no, this question/answer is not a duplicate, but a particular instance of a general class of problems, adding more cases to SO's repository on this issue.
At home: I code in Linux. LF used as line ending
At the office: I code in windows. CRLF used as line endings.
By default, git's autocrlf feature (https://stackoverflow.com/a/20653073/2715083) keeps things happy.
However, if you run a dual boot system with Linux and Windows, you can mess yourself up in the following way:
git pull some files you worked on in a linux environment in a windows environment, in a location that can be accessed from the dual-booted linux environment. This modifies the files to contain CRLF endings.
Then when you open up the file in linux, where the default is only LF, git diff will say entire file is modified, because each LF got changed to CRLF at every single line. (I was warned by Atom, which has this diff count inbuilt)
you are talking about text=auto part? I wasn't sure If I need to include that in a new .gitattributes file or not, because when I did, ATOM still showed the files as modified.
Yes, it does.
To force Git to apply .gitattributes directives, see "Dealing with line endings".
I would first make sure core.autocrlf is set to false.
git config --global core.autocrlf false
Then:
git add . -u
git commit -m "Saving files before refreshing line endings"
rm .git/index
git reset
git status
git add -u
git add .gitattributes
git commit -m "Normalize all the line endings"
You can also use, to force the index re-normalization:
git rm --cached -r .
git reset --hard
See "Force LF eol in git repo and working copy"
* text=auto eol=lf
The FIX
Delete/move to another location the problem files/folders
do git checkout <hash> <your/files/location>
where <hash> is for the last good commit, and your/files/location being the location of the files you want to cure from the CRLF problem. This will basically restore the older versions from your local .git repository.
Worked for me.
If you know something i missed, or explained incorrectly, do let me know

Linux + git: user's profile set git command tools

I'm using GitHub for my project.
There are a few bash scripts there. All of them contains:
set -e
set -o pipefail
Some of my team members can't run these scripts because they don't have git command line tools installed, I think so. Mentioned above lines raises an error.
So, I want to add git command line tools automatically for their user's profile.
I hope that adding something similar to:
echo "source <path_to_git_prompt>" > /etc/profile
should fix this issue, but there are a lot of things that I don't like in this approach:
It looks insecure for me (User's profile will be patched by some specific data)
I'll need to find git_prompt and other git command line tools in user's system which is not OK for me, because some of them uses Mint, somebody - Ubuntu, somebody - OS X, etc.
Well, how it may be managed? Is there better ways for adding there tools or maybe install them in some git hooks or so on?

How can I help git for Windows better handle a repository sitting on a Linux Samba share?

So I work with a Linux VM, I have several repos there with code that I run on the VM. I have a Samba share setup on the VM so I can access the repos from a Windows machine and edit them in Windows. There are many reasons why I have this setup but that would be beyond the scope of this question.
The editing experience is rather good but there is one thing left that's an annoyance: I use Atom on Windows to edit my files and it is great at handling changes within a file using git diff internally. However it colors a number of files as having changed when they have not.
To troubleshoot, I opened a command line on the Windows box and ran git status on the repo, it incorrectly showed a ton of files changed when there are actually no uncommitted changes in the repo. I do all of my git operations on the Linux box but it would be nice to at least have consistent status.
Is there some kind of git config on either the Linux or Windows side that I could use to make the two a little more compatible?
Ok, after digging some more, I've found the issue was due to different file mode flags because of my Samba configuration. I was able to fix things by disabling the fileMode option at the repo level:
git config --unset core.fileMode
And setting it globally on the Windows box:
git config --global core.fileMode true

Git problems with line endings differences between linux and windows

I'm working on a project on Windows and some project files seems to be changed locally but I didn't. Was ignoring them but now I cannot push because are unstaged files. When I look into this files differences, there isn't, only this line ending thing (CRLF, LF).
Tried to revert this files, reset --hard too.
Why can't I reset this files to repository HEAD?
Tried to do this too:
git config --global core.autocrlf false
If I do git reset --hard and git status later I get message that have many files with changes not staged.
Sorry but I don't know git and this linux/windows line ending differences very well.
Maybe someone else working on the project introduced bad line endings. two things 2 do:
fix bad line endings already committed.
align the team about the line endings policy.
See: Dealing with line endings.

Resources