简体   繁体   中英

How to setup git on windows with cygwin, git bash and git in a vagrant VM?

My Setup

We are using Windows 10 at work. I had the task to build a development VM with Vagrant which we all want to use.

We are mounting our git folders into the VM via the Vagrant SSH mount which works perfect for now.

We are also using Visual Studio Code as Editor.

My Goal

I want to use git in cygwin (for the windows users) and git in the VM seamlessly.

And of course we want to use the feature of Visual studio code to hightlight the changed files. As I understand it right Visual Studio Code is using the git implementation from the git bash. But this is a secondary requirement.

My config

On all machine I have the following .gitconfig :

[core]
    autocrlf = input
    editor = vim
    eol = lf
    filemode = false

My Problem

I clone a repo and the shells show me differnt outputs

git bash :

pwd
/c/Users/user/git/docker-install
>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitattributes

no changes added to commit (use "git add" and/or "git commit -a")
>git diff
diff --git a/.gitattributes b/.gitattributes
old mode 100755
new mode 100644

cygwin :

user@machine /cygdrive/c/Users/user/git/docker-install
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

user@machine /cygdrive/c/Users/user/git/docker-install
$ git diff

user@machine /cygdrive/c/Users/user/git/docker-install
$

Git vagrant VM :

[vagrant@vagrant docker-install (⎈ |minikube:default)]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitattributes

no changes added to commit (use "git add" and/or "git commit -a")
[vagrant@vagrant docker-install (⎈ |minikube:default)]$ git diff
diff --git a/.gitattributes b/.gitattributes
old mode 100755
new mode 100644
[vagrant@vagrant docker-install (⎈ |minikube:default)]$

My .gitattributes in this this repo

* text=auto

How should I setup my gitconfigs?

I read a lot of articles, spend a lot of time but I am still confused how we should setup our environment.

Can someone help me on this one?

First, Cygwin is not the only option: WSL (Windows Subsystem for Linux) is another option which would offer a true Linux-like experience.

Second, as noted, git config --global core.fileMode false is needed in Vagrant to ignore chmod.

But third, for files you know you want to be recorded with +x (755 instead of 644), irrespective of the OS ( like in Windows , which would ignore the execute permission), type ( with Git 2.9.1+ ):

git add --chmod=+x -- afile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM